alsa wav
wav_parser.h文件:
//File : wav_parser.h
//Author : Loon <sepnic@gmail.com> #ifndef __WAV_PARSER_H
#define __WAV_PARSER_H typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t; #if __BYTE_ORDER == __LITTLE_ENDIAN
#define COMPOSE_ID(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((d)<<24))
#define LE_SHORT(v) (v)
#define LE_INT(v) (v)
#define BE_SHORT(v) bswap_16(v)
#define BE_INT(v) bswap_32(v)
#elif __BYTE_ORDER == __BIG_ENDIAN
#define COMPOSE_ID(a,b,c,d) ((d) | ((c)<<8) | ((b)<<16) | ((a)<<24))
#define LE_SHORT(v) bswap_16(v)
#define LE_INT(v) bswap_32(v)
#define BE_SHORT(v) (v)
#define BE_INT(v) (v)
#else
#error "Wrong endian"
#endif #define WAV_RIFF COMPOSE_ID('R','I','F','F')
#define WAV_WAVE COMPOSE_ID('W','A','V','E')
#define WAV_FMT COMPOSE_ID('f','m','t',' ')
#define WAV_DATA COMPOSE_ID('d','a','t','a') /* WAVE fmt block constants from Microsoft mmreg.h header */
#define WAV_FMT_PCM 0x0001
#define WAV_FMT_IEEE_FLOAT 0x0003
#define WAV_FMT_DOLBY_AC3_SPDIF 0x0092
#define WAV_FMT_EXTENSIBLE 0xfffe /* Used with WAV_FMT_EXTENSIBLE format */
#define WAV_GUID_TAG "/x00/x00/x00/x00/x10/x00/x80/x00/x00/xAA/x00/x38/x9B/x71" /* it's in chunks like .voc and AMIGA iff, but my source say there
are in only in this combination, so I combined them in one header;
it works on all WAVE-file I have
*/
typedef struct WAVHeader {
uint32_t magic; /* 'RIFF' */
uint32_t length; /* filelen */
uint32_t type; /* 'WAVE' */
} WAVHeader_t; typedef struct WAVFmt {
uint32_t magic; /* 'FMT '*/
uint32_t fmt_size; /* 16 or 18 */
uint16_t format; /* see WAV_FMT_* */
uint16_t channels;
uint32_t sample_rate; /* frequence of sample */
uint32_t bytes_p_second;
uint16_t blocks_align; /* samplesize; 1 or 2 bytes */
uint16_t sample_length; /* 8, 12 or 16 bit */
} WAVFmt_t; typedef struct WAVFmtExtensible {
WAVFmt_t format;
uint16_t ext_size;
uint16_t bit_p_spl;
uint32_t channel_mask;
uint16_t guid_format; /* WAV_FMT_* */
uint8_t guid_tag[]; /* WAV_GUID_TAG */
} WAVFmtExtensible_t; typedef struct WAVChunkHeader {
uint32_t type; /* 'data' */
uint32_t length; /* samplecount */
} WAVChunkHeader_t; typedef struct WAVContainer {
WAVHeader_t header;
WAVFmt_t format;
WAVChunkHeader_t chunk;
} WAVContainer_t; int WAV_ReadHeader(int fd, WAVContainer_t *container); int WAV_WriteHeader(int fd, WAVContainer_t *container); #endif /* #ifndef __WAV_PARSER_H */
wav_parser.c
//File : wav_parser.c
//Author : Loon <sepnic@gmail.com> #include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h> #include "wav_parser.h" #define WAV_PRINT_MSG char *WAV_P_FmtString(uint16_t fmt)
{
switch (fmt) {
case WAV_FMT_PCM:
return "PCM";
break;
case WAV_FMT_IEEE_FLOAT:
return "IEEE FLOAT";
break;
case WAV_FMT_DOLBY_AC3_SPDIF:
return "DOLBY AC3 SPDIF";
break;
case WAV_FMT_EXTENSIBLE:
return "EXTENSIBLE";
break;
default:
break;
} return "NON Support Fmt";
} void WAV_P_PrintHeader(WAVContainer_t *container)
{
printf("+++++++++++++++++++++++++++/n");
printf("/n"); printf("File Magic: [%c%c%c%c]/n",
(char)(container->header.magic),
(char)(container->header.magic>>),
(char)(container->header.magic>>),
(char)(container->header.magic>>));
printf("File Length: [%d]/n", container->header.length);
printf("File Type: [%c%c%c%c]/n",
(char)(container->header.type),
(char)(container->header.type>>),
(char)(container->header.type>>),
(char)(container->header.type>>));
printf("/n");
printf("Fmt Magic: [%c%c%c%c]/n",
(char)(container->format.magic),
(char)(container->format.magic>>),
(char)(container->format.magic>>),
(char)(container->format.magic>>));
printf("Fmt Size: [%d]/n", container->format.fmt_size);
printf("Fmt Format: [%s]/n", WAV_P_FmtString(container->format.format));
printf("Fmt Channels: [%d]/n", container->format.channels);
printf("Fmt Sample_rate: [%d](HZ)/n", container->format.sample_rate);
printf("Fmt Bytes_p_second: [%d]/n", container->format.bytes_p_second);
printf("Fmt Blocks_align: [%d]/n", container->format.blocks_align);
printf("Fmt Sample_length: [%d]/n", container->format.sample_length); printf("/n"); printf("Chunk Type: [%c%c%c%c]/n",
(char)(container->chunk.type),
(char)(container->chunk.type>>),
(char)(container->chunk.type>>),
(char)(container->chunk.type>>));
printf("Chunk Length: [%d]/n", container->chunk.length); printf("/n");
printf("++++++++++++++++++++++++++++++++++++++/n");
} int WAV_P_CheckValid(WAVContainer_t *container)
{
if (container->header.magic != WAV_RIFF ||
container->header.type != WAV_WAVE ||
container->format.magic != WAV_FMT ||
container->format.fmt_size != LE_INT() ||
(container->format.channels != LE_SHORT() && container->format.channels != LE_SHORT())
|| container->chunk.type != WAV_DATA) {
fprintf(stderr, "non standard wav file./n");
return -;
} return ;
} int WAV_ReadHeader(int fd, WAVContainer_t *container)
{
assert((fd >=) && container); if (read(fd,&container->header,sizeof(container->header))!=sizeof(container->header)
||read(fd,&container->format,sizeof(container->format))!=sizeof(container->format)
||read(fd,&container->chunk,sizeof(container->chunk))!=sizeof(container->chunk)){ fprintf(stderr, "Error WAV_ReadHeader/n");
return -;
} if (WAV_P_CheckValid(container) < )
return -; #ifdef WAV_PRINT_MSG
WAV_P_PrintHeader(container);
#endif return ;
} int WAV_WriteHeader(int fd, WAVContainer_t *container)
{
assert((fd >=) && container); if (WAV_P_CheckValid(container) < )
return -; if (write(fd,&container->header,sizeof(container->header))!=sizeof(container->header)
||write(fd,&container->format,sizeof(container->format))!=sizeof(container->format)
||write(fd,&container->chunk,sizeof(container->chunk))!=sizeof(container->chunk)) {
fprintf(stderr, "Error WAV_WriteHeader/n");
return -;
} #ifdef WAV_PRINT_MSG
WAV_P_PrintHeader(container);
#endif return ;
}
sndwav_common.h
//File : sndwav_common.h
//Author : Loon <sepnic@gmail.com> #ifndef __SNDWAV_COMMON_H
#define __SNDWAV_COMMON_H #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "wav_parser.h" typedef long long off64_t; typedef struct SNDPCMContainer {
snd_pcm_t *handle;
snd_output_t *log;
snd_pcm_uframes_t chunk_size;
snd_pcm_uframes_t buffer_size;
snd_pcm_format_t format;
uint16_t channels;
size_t chunk_bytes;
size_t bits_per_sample;
size_t bits_per_frame; uint8_t *data_buf;
} SNDPCMContainer_t; ssize_t SNDWAV_ReadPcm(SNDPCMContainer_t *sndpcm, size_t rcount); ssize_t SNDWAV_WritePcm(SNDPCMContainer_t *sndpcm, size_t wcount); int SNDWAV_SetParams(SNDPCMContainer_t *sndpcm, WAVContainer_t *wav);
#endif /* #ifndef __SNDWAV_COMMON_H */
sndwav_common.c
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <alsa/asoundlib.h> #include "sndwav_common.h" int SNDWAV_P_GetFormat(WAVContainer_t *wav, snd_pcm_format_t *snd_format)
{
if (LE_SHORT(wav->format.format) != WAV_FMT_PCM)
return -; switch (LE_SHORT(wav->format.sample_length)) {
case :
*snd_format = SND_PCM_FORMAT_S16_LE;
break;
case :
*snd_format = SND_PCM_FORMAT_U8;
break;
default:
*snd_format = SND_PCM_FORMAT_UNKNOWN;
break;
} return ;
} ssize_t SNDWAV_ReadPcm(SNDPCMContainer_t *sndpcm, size_t rcount)
{
ssize_t r;
size_t result = ;
size_t count = rcount;
uint8_t *data = sndpcm->data_buf; if (count != sndpcm->chunk_size) {
count = sndpcm->chunk_size;
} while (count > ) {
r = snd_pcm_readi(sndpcm->handle, data, count);
if (r == -EAGAIN || (r >= && (size_t)r < count)) {
snd_pcm_wait(sndpcm->handle, );
} else if (r == -EPIPE) {
snd_pcm_prepare(sndpcm->handle);
fprintf(stderr, "<<<<<<<<<<<<<<< Buffer Underrun >>>>>>>>>>>>>>>/n");
} else if (r == -ESTRPIPE) {
fprintf(stderr, "<<<<<<<<<<<<<<< Need suspend >>>>>>>>>>>>>>>/n");
} else if (r < ) {
fprintf(stderr, "Error snd_pcm_writei: [%s]", snd_strerror(r));
exit(-);
} if (r > ) {
result += r;
count -= r;
data += r * sndpcm->bits_per_frame / ;
}
}
return rcount;
} ssize_t SNDWAV_WritePcm(SNDPCMContainer_t *sndpcm, size_t wcount)
{
ssize_t r;
ssize_t result = ;
uint8_t *data = sndpcm->data_buf; if (wcount < sndpcm->chunk_size) {
snd_pcm_format_set_silence(sndpcm->format,
data + wcount * sndpcm->bits_per_frame / ,
(sndpcm->chunk_size - wcount) * sndpcm->channels);
wcount = sndpcm->chunk_size;
}
while (wcount > ) {
r = snd_pcm_writei(sndpcm->handle, data, wcount);
if (r == -EAGAIN || (r >= && (size_t)r < wcount)) {
snd_pcm_wait(sndpcm->handle, );
} else if (r == -EPIPE) {
snd_pcm_prepare(sndpcm->handle);
fprintf(stderr, "<<<<<<<<<<<<<<< Buffer Underrun >>>>>>>>>>>>>>>/n");
} else if (r == -ESTRPIPE) {
fprintf(stderr, "<<<<<<<<<<<<<<< Need suspend >>>>>>>>>>>>>>>/n");
} else if (r < ) {
fprintf(stderr, "Error snd_pcm_writei: [%s]", snd_strerror(r));
exit(-);
}
if (r > ) {
result += r;
wcount -= r;
data += r * sndpcm->bits_per_frame / ;
}
}
return result;
} int SNDWAV_SetParams(SNDPCMContainer_t *sndpcm, WAVContainer_t *wav)
{
snd_pcm_hw_params_t *hwparams;
snd_pcm_format_t format;
uint32_t exact_rate;
uint32_t buffer_time, period_time; /* Allocate the snd_pcm_hw_params_t structure on the stack. */
snd_pcm_hw_params_alloca(&hwparams); /* Init hwparams with full configuration space */
if (snd_pcm_hw_params_any(sndpcm->handle, hwparams) < ) {
fprintf(stderr, "Error snd_pcm_hw_params_any/n");
goto ERR_SET_PARAMS;
} if (snd_pcm_hw_params_set_access(sndpcm->handle, hwparams
, SND_PCM_ACCESS_RW_INTERLEAVED) < ) {
fprintf(stderr, "Error snd_pcm_hw_params_set_access/n");
goto ERR_SET_PARAMS;
} /* Set sample format */
if (SNDWAV_P_GetFormat(wav, &format) < ) {
fprintf(stderr, "Error get_snd_pcm_format/n");
goto ERR_SET_PARAMS;
}
if (snd_pcm_hw_params_set_format(sndpcm->handle, hwparams, format) < ) {
fprintf(stderr, "Error snd_pcm_hw_params_set_format/n");
goto ERR_SET_PARAMS;
}
sndpcm->format = format; /* Set number of channels */
if (snd_pcm_hw_params_set_channels(sndpcm->handle, hwparams
, LE_SHORT(wav->format.channels)) < ) {
fprintf(stderr, "Error snd_pcm_hw_params_set_channels/n");
goto ERR_SET_PARAMS;
}
sndpcm->channels = LE_SHORT(wav->format.channels); /* Set sample rate. If the exact rate is not supported */
/* by the hardware, use nearest possible rate. */
exact_rate = LE_INT(wav->format.sample_rate);
if (snd_pcm_hw_params_set_rate_near(sndpcm->handle, hwparams, &exact_rate, ) < ) {
fprintf(stderr, "Error snd_pcm_hw_params_set_rate_near/n");
goto ERR_SET_PARAMS;
}
if (LE_INT(wav->format.sample_rate) != exact_rate) {
fprintf(stderr
, "The rate %d Hz is not supported by your hardware./n ==> Using %d Hz instead./n",
LE_INT(wav->format.sample_rate), exact_rate);
} if (snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time, ) < ) {
fprintf(stderr, "Error snd_pcm_hw_params_get_buffer_time_max/n");
goto ERR_SET_PARAMS;
}
if (buffer_time > ) buffer_time = ;
period_time = buffer_time / ; if (snd_pcm_hw_params_set_buffer_time_near(sndpcm->handle, hwparams
, &buffer_time, ) < ) {
fprintf(stderr, "Error snd_pcm_hw_params_set_buffer_time_near/n");
goto ERR_SET_PARAMS;
} if (snd_pcm_hw_params_set_period_time_near(sndpcm->handle, hwparams
, &period_time, ) < ) {
fprintf(stderr, "Error snd_pcm_hw_params_set_period_time_near/n");
goto ERR_SET_PARAMS;
} /* Set hw params */
if (snd_pcm_hw_params(sndpcm->handle, hwparams) < ) {
fprintf(stderr, "Error snd_pcm_hw_params(handle, params)/n");
goto ERR_SET_PARAMS;
} snd_pcm_hw_params_get_period_size(hwparams, &sndpcm->chunk_size, );
snd_pcm_hw_params_get_buffer_size(hwparams, &sndpcm->buffer_size);
if (sndpcm->chunk_size == sndpcm->buffer_size) {
fprintf(stderr, ("Can't use period equal to buffer size (%lu == %lu)/n")
, sndpcm->chunk_size, sndpcm->buffer_size);
goto ERR_SET_PARAMS;
} sndpcm->bits_per_sample = snd_pcm_format_physical_width(format);
sndpcm->bits_per_frame = sndpcm->bits_per_sample * LE_SHORT(wav->format.channels); sndpcm->chunk_bytes = sndpcm->chunk_size * sndpcm->bits_per_frame / ; /* Allocate audio data buffer */
sndpcm->data_buf = (uint8_t *)malloc(sndpcm->chunk_bytes);
if (!sndpcm->data_buf) {
fprintf(stderr, "Error malloc: [data_buf]/n");
goto ERR_SET_PARAMS;
} return ; ERR_SET_PARAMS:
return -;
}
lplay.c
#include <stdio.h>
#include <malloc.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
#include <locale.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <alsa/asoundlib.h>
#include <assert.h>
#include "wav_parser.h"
#include "sndwav_common.h" ssize_t SNDWAV_P_SaveRead(int fd, void *buf, size_t count)
{
ssize_t result = , res; while (count > ) {
if ((res = read(fd, buf, count)) == )
break;
if (res < )
return result > ? result : res;
count -= res;
result += res;
buf = (char *)buf + res;
}
return result;
} void SNDWAV_Play(SNDPCMContainer_t *sndpcm, WAVContainer_t *wav, int fd)
{
int load, ret;
off64_t written = ;
off64_t c;
off64_t count = LE_INT(wav->chunk.length); load = ;
while (written < count) {
/* Must read [chunk_bytes] bytes data enough. */
do {
c = count - written;
if (c > sndpcm->chunk_bytes)
c = sndpcm->chunk_bytes;
c -= load; if (c == )
break;
ret = SNDWAV_P_SaveRead(fd, sndpcm->data_buf + load, c);
if (ret < ) {
fprintf(stderr, "Error safe_read/n");
exit(-);
}
if (ret == )
break;
load += ret;
} while ((size_t)load < sndpcm->chunk_bytes); /* Transfer to size frame */
load = load * / sndpcm->bits_per_frame;
ret = SNDWAV_WritePcm(sndpcm, load);
if (ret != load)
break; ret = ret * sndpcm->bits_per_frame / ;
written += ret;
load = ;
}
} int main(int argc, char *argv[])
{
char *filename;
char *devicename = "default";
int fd;
WAVContainer_t wav;
SNDPCMContainer_t playback; if (argc != ) {
fprintf(stderr, "Usage: ./lplay <FILENAME>/n");
return -;
} memset(&playback, 0x0, sizeof(playback)); filename = argv[];
fd = open(filename, O_RDONLY);
if (fd < ) {
fprintf(stderr, "Error open [%s]/n", filename);
return -;
} if (WAV_ReadHeader(fd, &wav) < ) {
fprintf(stderr, "Error WAV_Parse [%s]/n", filename);
goto Err;
} if (snd_output_stdio_attach(&playback.log, stderr, ) < ) {
fprintf(stderr, "Error snd_output_stdio_attach/n");
goto Err;
} if (snd_pcm_open(&playback.handle, devicename, SND_PCM_STREAM_PLAYBACK, ) < ) {
fprintf(stderr, "Error snd_pcm_open [ %s]/n", devicename);
goto Err;
} if (SNDWAV_SetParams(&playback, &wav) < ) {
fprintf(stderr, "Error set_snd_pcm_params/n");
goto Err;
}
snd_pcm_dump(playback.handle, playback.log); SNDWAV_Play(&playback, &wav, fd); snd_pcm_drain(playback.handle); close(fd);
free(playback.data_buf);
snd_output_close(playback.log);
snd_pcm_close(playback.handle);
return ; Err:
close(fd);
if (playback.data_buf) free(playback.data_buf);
if (playback.log) snd_output_close(playback.log);
if (playback.handle) snd_pcm_close(playback.handle);
return -;
}
lrecord.c
#include <stdio.h>
#include <malloc.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
#include <locale.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <alsa/asoundlib.h>
#include <assert.h>
#include "wav_parser.h"
#include "sndwav_common.h" #define DEFAULT_CHANNELS (2)
#define DEFAULT_SAMPLE_RATE (8000)
#define DEFAULT_SAMPLE_LENGTH (16)
#define DEFAULT_DURATION_TIME (10) int SNDWAV_PrepareWAVParams(WAVContainer_t *wav)
{
assert(wav); uint16_t channels = DEFAULT_CHANNELS;
uint16_t sample_rate = DEFAULT_SAMPLE_RATE;
uint16_t sample_length = DEFAULT_SAMPLE_LENGTH;
uint32_t duration_time = DEFAULT_DURATION_TIME; /* Const */
wav->header.magic = WAV_RIFF;
wav->header.type = WAV_WAVE;
wav->format.magic = WAV_FMT;
wav->format.fmt_size = LE_INT();
wav->format.format = LE_SHORT(WAV_FMT_PCM);
wav->chunk.type = WAV_DATA; /* User definition */
wav->format.channels = LE_SHORT(channels);
wav->format.sample_rate = LE_INT(sample_rate);
wav->format.sample_length = LE_SHORT(sample_length); /* See format of wav file */
wav->format.blocks_align = LE_SHORT(channels * sample_length / );
wav->format.bytes_p_second = LE_INT((uint16_t)(wav->format.blocks_align) * sample_rate); wav->chunk.length = LE_INT(duration_time * (uint32_t)(wav->format.bytes_p_second));
wav->header.length = LE_INT((uint32_t)(wav->chunk.length) +/
sizeof(wav->chunk) + sizeof(wav->format) + sizeof(wav->header) - ); return ;
} void SNDWAV_Record(SNDPCMContainer_t *sndpcm, WAVContainer_t *wav, int fd)
{
off64_t rest;
size_t c, frame_size; if (WAV_WriteHeader(fd, wav) < ) {
exit(-);
} rest = wav->chunk.length;
while (rest > ) {
c = (rest <= (off64_t)sndpcm->chunk_bytes) ? (size_t)rest : sndpcm->chunk_bytes;
frame_size = c * / sndpcm->bits_per_frame;
if (SNDWAV_ReadPcm(sndpcm, frame_size) != frame_size)
break; if (write(fd, sndpcm->data_buf, c) != c) {
fprintf(stderr, "Error SNDWAV_Record[write]/n");
exit(-);
} rest -= c;
}
} int main(int argc, char *argv[])
{
char *filename;
char *devicename = "default";
int fd;
WAVContainer_t wav;
SNDPCMContainer_t record; if (argc != ) {
fprintf(stderr, "Usage: ./lrecord <FILENAME>/n");
return -;
} memset(&record, 0x0, sizeof(record)); filename = argv[];
remove(filename);
if ((fd = open(filename, O_WRONLY | O_CREAT, )) == -) {
fprintf(stderr, "Error open: [%s]/n", filename);
return -;
} if (snd_output_stdio_attach(&record.log, stderr, ) < ) {
fprintf(stderr, "Error snd_output_stdio_attach/n");
goto Err;
} if (snd_pcm_open(&record.handle, devicename, SND_PCM_STREAM_CAPTURE, ) < ) {
fprintf(stderr, "Error snd_pcm_open [ %s]/n", devicename);
goto Err;
} if (SNDWAV_PrepareWAVParams(&wav) < ) {
fprintf(stderr, "Error SNDWAV_PrepareWAVParams/n");
goto Err;
} if (SNDWAV_SetParams(&record, &wav) < ) {
fprintf(stderr, "Error set_snd_pcm_params/n");
goto Err;
}
snd_pcm_dump(record.handle, record.log); SNDWAV_Record(&record, &wav, fd); snd_pcm_drain(record.handle); close(fd);
free(record.data_buf);
snd_output_close(record.log);
snd_pcm_close(record.handle);
return ; Err:
close(fd);
remove(filename);
if (record.data_buf) free(record.data_buf);
if (record.log) snd_output_close(record.log);
if (record.handle) snd_pcm_close(record.handle);
return -;
}
makefile
CC =/home/yuanpengjun/ngi/prebuilt/toolchains/arm-fsl-Linux-gnueabi/4.6./bin/arm-fsl-linux-gnueabi-gcc
CFLAGS = -g -Wall -O0 -I/home/yuanpengjun/ngi/externals/alsa-lib/include
LIBS = -L/home/yuanpengjun/ngi/out/target/product/rome/system/usr/lib -lasound lplay: lplay.o sndwav_common.o wav_parser.o
$(CC) $(CFLAGS) lplay.o sndwav_common.o wav_parser.o -o lplay $(LIBS) lplay.o: lplay.c sndwav_common.h wav_parser.h $(CC) $(CFLAGS) -c lplay.c lrecord: lrecord.o sndwav_common.o wav_parser.o $(CC) $(CFLAGS) lrecord.o sndwav_common.o wav_parser.o -o lrecord $(LIBS) lrecord.o: lrecord.c sndwav_common.h wav_parser.h $(CC) $(CFLAGS) -c lrecord.c sndwav_common.o: sndwav_common.c sndwav_common.h $(CC) $(CFLAGS) -c sndwav_common.c wav_parser.o: wav_parser.c wav_parser.h $(CC) $(CFLAGS) -c wav_parser.c clean: rm lplay lrecord *.o
alsa wav的更多相关文章
- 基于ALSA的WAV播放和录音程序
http://blog.csdn.net/azloong/article/details/6140824 这段时间在探索ALSA架构,从ALSA Core到ALSA Lib,再到Android Aud ...
- 基于Linux ALSA音频驱动的wav文件解析及播放程序 2012
本设计思路:先打开一个普通wav音频文件,从定义的文件头前面的44个字节中,取出文件头的定义消息,置于一个文件头的结构体中.然后打开alsa音频驱动,从文件头结构体取出采样精度,声道数,采样频率三个重 ...
- linux下alsa架构音频驱动播放wav格式文件
#include<stdio.h> #include<stdlib.h> #include <string.h> #include <alsa/asoundl ...
- Linux音频编程--使用ALSA库播放wav文件
在UBUNTU系统上使用alsa库完成了对外播放的wav文件的案例. 案例代码: /** *test.c * *注意:这个例子在Ubuntu 12.04.1环境下编译运行成功. * */ #inclu ...
- ALSA 学习小记
对于playback snd_pcm_begin snd_pcm_commit, 貌似 commit给的frame才会使得alsa去把数据填充 转自 http://magodo.github.io/ ...
- alsa音频驱动科普第一课
做linux音频编程对alsa应该不陌生. 但是对于刚接触这块技术的同学来说是一件困难的事情.原因在于:网上关于alsa的资料太少了,特别国内的资料更是大部分重复.对于初学者来说特别苦恼. 由于笔者经 ...
- Alsa 读取wave文件,并播放wave 文件
对于一个wave文件,如果需要播放,涉及到几个方面 1.对于wave文件的解析 2.通过解析wave文件,将得到的参数(主要是sampfrequency, bitsperSample,channel) ...
- alsa声卡分析alsa-utils调用过程
如何分析tinyplay 播放音频和tinymix的过程?需要相应的工具来支持追查: 一.利用strace工具分析tinyplay和tinymix: strace -o tinyplay.log ti ...
- 基于Orangpi Zero和Linux ALSA实现WIFI无线音箱(三)
作品已经完成,先上源码: https://files.cnblogs.com/files/qzrzq1/WIFISpeaker.zip 全文包含三篇,这是第三篇,主要讲述接收端程序的原理和过程. 第一 ...
随机推荐
- keras系列︱图像多分类训练与利用bottleneck features进行微调(三)
引自:http://blog.csdn.net/sinat_26917383/article/details/72861152 中文文档:http://keras-cn.readthedocs.io/ ...
- 教你如何禁用U盘、屏蔽USB端口的三种方法
如果想禁止所有U盘的使用,则可以通过修改注册表来实现. 打开”运行“对话框,输入命令“Regedit”进入注册表界面. 依次展开“HKEY_LOCAL_MACHINE”→“SYSTEM”→“ Cu ...
- 接口与virtual,override,new关键字
一,类继承接口 1,首先我们定义一个简单的ITeacher接口,并定义一个Professor类继承它. public interface ITeacher { void Print(); } publ ...
- PCL点云配准(1)
在逆向工程,计算机视觉,文物数字化等领域中,由于点云的不完整,旋转错位,平移错位等,使得要得到的完整的点云就需要对局部点云进行配准,为了得到被测物体的完整数据模型,需要确定一个合适的坐标系,将从各个视 ...
- SpringMVC深度探险(一) —— SpringMVC前传
在我们熟知的建立在三层结构(表示层.业务逻辑层.持久层)基础之上的J2EE应用程序开发之中,表示层的解决方案最多.因为在表示层自身的知识触角很多,需要解决的问题也不少,这也就难免造成与之对应的解决方案 ...
- jquery 实现下拉菜单
Jquery 是一个轻量的框架,个人认为非常好用,今天就写一个非常简单的例子,实现下拉菜单功能: 首先肯定要在页面引用jquery.js 版本不限 : 接下来把=================== ...
- [转]Idea2016 使用Maven配置简单Web项目(受益比较多的一篇)
最近被同事一直吵着用Idea写Java,于是偷偷的去试用了一下Idea.确实不错,无论界面还是智能提醒都是蛮符合我的使用习惯,但是刚从Eclipse出来,使用Idea还是不太习惯的.所以这里写出来,供 ...
- (笔记)Linux下的CGI和BOA使用期间遇到的问题汇总
前段时间在做C/S模式下的视频监控,这段时间是B/S模式下的.期间遇到了不少问题,有些问题一卡就是几天,有些问题的解决办法在办法在网上也不是很好找,所以还有些问题虽然得到了临时解决,但是其原理现在我本 ...
- python 调用 C语言函数
python可以直接调用C语言的函数,本文记录用ctypes调用c语言的方法. test.c #include <stdio.h> int test(char *temp) { print ...
- 使用Maven构建项目
要构建一个基于Maven的项目,打开控制台,进入到 pom.xml 文件所放的项目文件夹,并发出以下命令: mvn package 这将执行Maven的“package”阶段. Maven构建生命周期 ...