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 全文包含三篇,这是第三篇,主要讲述接收端程序的原理和过程. 第一 ...
随机推荐
- [开发笔记]-C#获取pdf文档的页数
[操作pdf文档]之C#判断pdf文档的页数: /// <summary> /// 获取pdf文档的页数 /// </summary> /// <param name=& ...
- kafka集群中jmx端口设置
jmx端口主要用来监控kafka集群的. 在启动kafka的脚本kafka-server-start.sh中找到堆设置,添加export JMX_PORT="9999" if [ ...
- 15.01.29-MVC中用Areas分解项目
在MVC项目上右键->新建->区域(Areas)...,将会自动生成Areas文件夹,并在文件夹下创建Model+Controller+View的mvc框架.在Views文件夹中,自动生成 ...
- json转实体,json转List实体,json转泛型实体
1.========================= https://segmentfault.com/a/1190000009523164 package com.thunisoft.maybee ...
- qt configure参数配置介绍
======================================全文是按照./configure -help来翻译的==================================== ...
- QT:KeepAliveOption的应用
由于用QTcpSocket写网络通讯程序,当正常服务端或者客户端断开的时候,我们监测信号即可:Signals:stateChanged(QAbstractSocket::SocketState).(手 ...
- 如何将Mac系统OS X Yosemite装到外部磁盘?(转)
有Mac用户想了解是否可以将 OS X Yosemite 装到替代的外部磁盘,答案是肯定的,有需求的用户,可以按照本篇教程逐步进行. 前面我已经写过一篇文章介绍了如何安装 OS X Yosemite ...
- Ogre1.9 源码编译
我们首先需要下载. 1.cmake http://www.cmake.org/download/ (选择window安装包最方便) 2.Ogre1.9源代码 https://bitbucket.org ...
- "android.uid.systemandroid.view.InflateException: Binary XML file line #7: Error inflating class android.webkit.WebView
在android源码中编译app通过,运行时出现错误: "android.uid.systemandroid.view.InflateException: Binary XML file l ...
- 【总结】牛客职播第九期:您的美团点评offer已送到门口,快来与我们一起影响世界!
一.介绍 美团点评2018校园春招流程介绍&面试答疑 讲师:燕鹏.Taylor 二.收获 面试时如果太紧张或者内向,容易吃亏,所以建议把面试当做展示自己的一次舞台. 遇见一道编程题目,如果无法 ...