对于一个wave文件,如果需要播放,涉及到几个方面

1.对于wave文件的解析

2.通过解析wave文件,将得到的参数(主要是sampfrequency, bitsperSample,channel)通过alsa api设下去

3.正确找到data的起始点

4.play alsa

1.对于wave文件的解析,需要知道wave文件的格式

注意几点,标准的是44byte的头,但是有些情况下会有additional info, 占据2字节。头信息参见下图,也可以参考wave 文件解析

endian

field name

Size

 
big ChunkID 4 文件头标识,一般就是" RIFF" 四个字母
little ChunkSize 4 整个数据文件的大小,不包括上面ID和Size本身
big Format 4 一般就是" WAVE" 四个字母
big SubChunk1ID 4 格式说明块,本字段一般就是"fmt "
little SubChunk1Size 4 本数据块的大小,不包括ID和Size字段本身
little AudioFormat 2 音频的格式说明
little NumChannels 2 声道数
little SampleRate 4 采样率
little ByteRate 4 比特率,每秒所需要的字节数
little BlockAlign 2 数据块对齐单元
little BitsPerSample 2 采样时模数转换的分辨率
big SubChunk2ID 4 真正的声音数据块,本字段一般是"data"
little SubChunk2Size 4 本数据块的大小,不包括ID和Size字段本身
little Data N 音频的采样数据

2.设置alsa的参数可以详见代码

3.通过解析wave file可以知道我们data的起始位置

4.通过alsa来play,详见代码

  1. /**
  2. @file TestAlsaPlayWave.cpp
  3. @brief This is a short example to play the audio wave, please define the path in the main func
  4. @par author: jlm
  5. @par pre env: alsa
  6. @todo
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string>
  12. #include <sched.h>
  13. #include <errno.h>
  14. #include <getopt.h>
  15. #include <iostream>
  16. #include <asoundlib.h>
  17. #include <sys/time.h>
  18. #include <math.h>
  19. using namespace std;
  20.  
  21. /*********Type definition***********************/
  22. typedef unsigned char uint8;
  23. typedef unsigned short uint16;
  24.  
  25. typedef enum EBitsPerSample
  26. {
  27. BITS_UNKNOWN = ,
  28. BITS_PER_SAMPLE_8 = ,
  29. BITS_PER_SAMPLE_16 = ,
  30. BITS_PER_SAMPLE_32 =
  31. }EBitsPerSample_t;
  32.  
  33. typedef enum ENumOfChannels
  34. {
  35. NUM_OF_CHANNELS_1 = ,
  36. NUM_OF_CHANNELS_2 =
  37. }ENumOfChannels_t;
  38.  
  39. #if 0
  40. /** PCM state */
  41. typedef enum _snd_pcm_state {
  42. /** Open */
  43. SND_PCM_STATE_OPEN = ,
  44. /** Setup installed */
  45. SND_PCM_STATE_SETUP,
  46. /** Ready to start */
  47. SND_PCM_STATE_PREPARED,
  48. /** Running */
  49. SND_PCM_STATE_RUNNING,
  50. /** Stopped: underrun (playback) or overrun (capture) detected */
  51. SND_PCM_STATE_XRUN,
  52. /** Draining: running (playback) or stopped (capture) */
  53. SND_PCM_STATE_DRAINING,
  54. /** Paused */
  55. SND_PCM_STATE_PAUSED,
  56. /** Hardware is suspended */
  57. SND_PCM_STATE_SUSPENDED,
  58. /** Hardware is disconnected */
  59. SND_PCM_STATE_DISCONNECTED,
  60. SND_PCM_STATE_LAST = SND_PCM_STATE_DISCONNECTED
  61. } snd_pcm_state_t;
  62. #endif
  63.  
  64. typedef struct ALSA_CONFIGURATION
  65. {
  66.  
  67. std::string alsaDevice;
  68.  
  69. std::string friendlyName;
  70.  
  71. /// Read: Buffer size should be large enough to prevent overrun (read / write buffer full)
  72. unsigned int alsaBufferSize;
  73.  
  74. /// Chunk size should be smaller to prevent underrun (write buffer empty)
  75. unsigned int alsaPeriodFrame;
  76.  
  77. unsigned int samplingFrequency;//48kHz
  78.  
  79. EBitsPerSample bitsPerSample;
  80.  
  81. ENumOfChannels numOfChannels;
  82.  
  83. bool block; // false means nonblock
  84.  
  85. snd_pcm_access_t accessType;
  86.  
  87. snd_pcm_stream_t streamType; // Playback or capture
  88.  
  89. unsigned int alsaCapturePeriod; // Length of each capture period
  90. }Alsa_Conf;
  91.  
  92. typedef struct Wave_Header
  93. {
  94. uint8 ChunkID[];
  95. uint8 ChunkSize[];
  96. uint8 Format[];
  97. uint8 SubChunk1ID[];
  98. uint8 SubChunk1Size[];
  99. uint8 AudioFormat[];
  100. uint8 NumChannels[];
  101. uint8 SampleRate[];
  102. uint8 ByteRate[];
  103. uint8 BlockAlign[];
  104. uint8 BitsPerSample[];
  105. uint8 CombineWaveFileExtra2Bytes[];
  106. uint8 SubChunk2ID[];
  107. uint8 SubChunk2Size[];
  108. }Wave_Header_t;
  109.  
  110. typedef struct Wave_Header_Size_Info
  111. {
  112. uint8 ChunkID[];
  113. uint8 ChunkSize[];
  114. uint8 Format[];
  115. uint8 SubChunk1ID[];
  116. uint8 SubChunk1Size[];
  117. }Wave_Header_Size_Info_t;
  118.  
  119. typedef struct Wave_Header_Audio_Info
  120. {
  121. uint8 AudioFormat[];
  122. uint8 NumChannels[];
  123. uint8 SampleRate[];
  124. uint8 ByteRate[];
  125. uint8 BlockAlign[];
  126. uint8 BitsPerSample[];
  127. }Wave_Header_Audio_Info_t;
  128.  
  129. typedef struct Wave_Header_Additional_Info
  130. {
  131. uint8 AdditionalInfo_2Bytes[]; //this depends on the SubChunk1Size,normal if SubChunk1Size=16 then match the normal wave format, if SubChunk1Size=18 then 2 more additional info bytes
  132. }Wave_Header_Additional_Info_t;
  133.  
  134. typedef struct Wave_Header_Data_Info
  135. {
  136. uint8 SubChunk2ID[];
  137. uint8 SubChunk2Size[];
  138. }Wave_Header_Data_Info_t;
  139.  
  140. /*********Global Variable***********************/
  141. snd_pcm_uframes_t g_frames; //just test purpose
  142.  
  143. /*********Func Declaration***********************/
  144. void TestAlsaDevice(snd_pcm_t** phandler);
  145. bool PrepareAlsaDevice(Alsa_Conf* palsaCfg,snd_pcm_t** phandler);
  146. bool closeAlsaDevice(snd_pcm_t** phandler);
  147. bool ParseWaveFile(const string wavepath,Alsa_Conf* palsaCfg);
  148. uint16 HandleLittleEndian(uint8* arr,int size);
  149. bool PlayWave(FILE** fp,snd_pcm_t** phandler,Alsa_Conf* palsaCfg);
  150.  
  151. uint16 HandleLittleEndian(uint8* arr,int size)
  152. {
  153. uint16 value=;
  154. ;i<size;i++)
  155. {
  156. value=value+(arr[i]<<(*i));
  157. }
  158. return value;
  159. }
  160.  
  161. #if 0
  162. //this is the return value
  163. ChunkID = "RIFF"
  164. ChunkSize =
  165. Format = "WAVE"
  166. fmt = "fmt "
  167. SubChunk1Size =
  168. AudioFormat =
  169. NumChannels =
  170. SampleRate =
  171. ByteRate =
  172. BlockAlign =
  173. BitsPerSample =
  174. SubChunk2ID = "data"
  175. SubChunk2Size =
  176. #endif
  177.  
  178. //parse the wave file
  179. bool ParseWaveFile(const string wavepath,Alsa_Conf* palsaCfg,FILE** fp)
  180. {
  181. ;
  182. //FILE* fp=NULL;
  183. *fp=fopen(wavepath.c_str(),"rb");
  184. if(*fp==NULL)
  185. {
  186. cout<<"Can parse the wave file-->need check the file name"<<endl;
  187. }
  188.  
  189. /*********************size info parse begin*************************/
  190. //read size info
  191. Wave_Header_Size_Info_t wav_size_info;
  192. memset(&wav_size_info,,sizeof(Wave_Header_Size_Info_t));
  193. ret=fread(&wav_size_info,,*fp);
  194.  
  195. )
  196. {
  197. cout<<"read error"<<endl;
  198. return false;
  199. }
  200. string ChunkID="";
  201. ;i<;i++)
  202. {
  203. ChunkID+=wav_size_info.ChunkID[i];
  204. }
  205. string riff="RIFF";
  206. !=strcmp(ChunkID.c_str(),riff.c_str()))
  207. {
  208. cout<<"Invalid the fist Chunk id"<<endl;
  209. return false;
  210. }
  211.  
  212. uint16 ChunkSize=HandleLittleEndian(wav_size_info.ChunkSize,);
  213. cout<<"The ChunSize is "<<ChunkSize<<endl;
  214.  
  215. string Format="";
  216. ;i<;i++)
  217. {
  218. Format+=wav_size_info.Format[i];
  219. }
  220.  
  221. !=strcmp(Format.c_str(),"WAVE"))
  222. {
  223. cout<<"Invalid the format"<<endl;
  224. return false;
  225. }
  226.  
  227. string SubChunk1ID="";
  228. ;i<;i++)
  229. {
  230. SubChunk1ID+=wav_size_info.SubChunk1ID[i];
  231. }
  232. string fmt="fmt ";
  233. !=strcmp(SubChunk1ID.c_str(),fmt.c_str()))
  234. {
  235. cout<<"Invalid the SubChunk1ID "<<endl;
  236. return false;
  237. }
  238. uint16 SubChunk1Size=HandleLittleEndian(wav_size_info.SubChunk1Size,);
  239.  
  240. && SubChunk1Size!=)
  241. {
  242. cout<<"Invalid the SubChunk1Size"<<endl;
  243. return false;
  244. }
  245. /*********************Audio info parse begin*************************/
  246. Wave_Header_Audio_Info_t wav_audio_info;
  247. memset(&wav_audio_info,,sizeof(Wave_Header_Audio_Info_t));
  248. ret=fread(&wav_audio_info,,*fp);
  249. )
  250. {
  251. cout<<"read error"<<endl;
  252. return false;
  253. }
  254. //fseek(fp,sizeof(Wave_Header_Size_Info_t),0);//文件指针偏移3个字节到'2' because fread will shift the pointer
  255. uint16 AudioFormat =HandleLittleEndian(wav_audio_info.AudioFormat,);
  256.  
  257. uint16 NumChannels =HandleLittleEndian(wav_audio_info.NumChannels,);
  258.  
  259. uint16 SampleRate =HandleLittleEndian(wav_audio_info.SampleRate,);
  260.  
  261. uint16 ByteRate =HandleLittleEndian(wav_audio_info.ByteRate,);
  262.  
  263. uint16 BlockAlign =HandleLittleEndian(wav_audio_info.BlockAlign,);
  264.  
  265. uint16 BitsPerSample=HandleLittleEndian(wav_audio_info.BitsPerSample,);
  266.  
  267. palsaCfg->numOfChannels=(ENumOfChannels)NumChannels;
  268. palsaCfg->samplingFrequency=SampleRate;
  269. palsaCfg->bitsPerSample=(EBitsPerSample)BitsPerSample;
  270.  
  271. /*********************Additional info parse begin if needed*************************/
  272. )
  273. {
  274. Wave_Header_Additional_Info_t wav_additional_info;
  275. memset(&wav_additional_info,,sizeof(Wave_Header_Additional_Info_t));
  276. fread(&wav_additional_info,,*fp);
  277.  
  278. cout<<"read wav_additional_info"<<endl;
  279. )
  280. {
  281. cout<<"read error"<<endl;
  282. return false;
  283. }
  284. uint16 AdditionalInfo=HandleLittleEndian(wav_additional_info.AdditionalInfo_2Bytes,);
  285. cout<<"read AdditionalInfo value="<<AdditionalInfo<<endl;
  286.  
  287. }
  288.  
  289. /*********************Data info parse begin *************************/
  290. Wave_Header_Data_Info_t wave_data_info;
  291. memset(&wave_data_info,,sizeof(Wave_Header_Data_Info_t));
  292. fread(&wave_data_info,,*fp);
  293.  
  294. )
  295. {
  296. cout<<"read error"<<endl;
  297. return false;
  298. }
  299. string SubChunk2ID="";
  300. ;i<;i++)
  301. {
  302. SubChunk2ID+=wave_data_info.SubChunk2ID[i];
  303. }
  304. string fact="fact";
  305. string data="data";
  306. ==strcmp(SubChunk2ID.c_str(),fact.c_str()))
  307. {
  308. cout<<"SubChunk2ID fact"<<endl;
  309. }
  310. ==strcmp(SubChunk2ID.c_str(),data.c_str()))
  311. {
  312. cout<<"SubChunk2ID data"<<endl;
  313. }
  314. else
  315. {
  316. cout<<"Invalid SubChunk2ID "<<endl;
  317. return false;
  318. }
  319. uint16 SubChunk2Size=HandleLittleEndian(wave_data_info.SubChunk2Size,);
  320.  
  321. cout<<"End Parse"<<endl;
  322. return true;
  323. }
  324.  
  325. bool PlayWave(FILE** fp,snd_pcm_t** phandler,Alsa_Conf* palsaCfg)
  326. {
  327.  
  328. ;
  329. bool ret=false;
  330. snd_pcm_uframes_t frames=palsaCfg->alsaPeriodFrame;
  331. ; //4bytes
  332. uint16 audio_data_size=frames*bytesPerFrame;//one period 10ms ,1600*10/1000*(2*16/8)=640bytes one period
  333. uint8* buffer=new uint8[audio_data_size];
  334. cout<<"Start play wave"<<endl;
  335.  
  336. if(*fp==NULL || *phandler==NULL || palsaCfg==NULL)
  337. {
  338. cout<<"End play wave because something is NULL"<<endl;
  339. return false;
  340. }
  341. //fseek(*fp,46,SEEK_SET); //no need to do fseek because already shifted
  342. cout<<"available frame "<<snd_pcm_avail(*phandler)<<"my frames is "<<frames<<endl;
  343.  
  344. while(true)
  345. {
  346. if(feof(*fp))
  347. {
  348. cout<<"Reach end of the file"<<endl;
  349. break;
  350. }
  351. else
  352. {
  353. if(snd_pcm_avail(*phandler)<frames)
  354. {
  355. continue;
  356. }
  357. else
  358. {
  359. memset(reinterpret_cast<,sizeof(uint8)*audio_data_size);
  360. err=fread(buffer,,*fp);
  361. )
  362. {
  363. cout<<"read error"<<endl;
  364. }
  365. if ( NULL != buffer )
  366. {
  367. err = snd_pcm_writei(*phandler, buffer, frames);
  368. )
  369. {
  370. cout<<"Fail to write the audio data to ALSA. Reason: "<<(snd_strerror(err));
  371. // recover ALSA device
  372. err = snd_pcm_recover(*phandler, err, );
  373. )
  374. {
  375. cout<<"Fail to recover ALSA device. Reason: "<<(snd_strerror(err));
  376. ret = false;
  377. }
  378. else
  379. {
  380. cout<<"ALSA device is recovered from error state"<<endl;
  381. }
  382. }
  383. }
  384. else
  385. {
  386. cout<<"Write buffer is NULL!"<<endl;
  387. }
  388. }
  389. }
  390. usleep(palsaCfg->alsaCapturePeriod / ( * ));
  391. }
  392. delete[] buffer;
  393. buffer=NULL;
  394. return ret;
  395. }
  396. bool PrepareAlsaDevice(Alsa_Conf* palsaCfg,snd_pcm_t** phandler)
  397. {
  398. bool ret=false;
  399. bool success=true;
  400. ;
  401. snd_pcm_format_t format;
  402. snd_pcm_hw_params_t *hw_params = NULL;
  403. ;
  404. if(palsaCfg!=NULL)
  405. {
  406. // open ALSA device
  407. error=snd_pcm_open(phandler,palsaCfg->alsaDevice.c_str(),palsaCfg->streamType,palsaCfg->block? :SND_PCM_NONBLOCK);
  408. ) //0 on success otherwise a negative error code
  409. {
  410. success=false;
  411. cout<<"Open Alsadevice error error code="<<snd_strerror(error)<<endl;
  412. }
  413.  
  414. if(success)
  415. {
  416. //allocate hardware parameter structur
  417. error=snd_pcm_hw_params_malloc(&hw_params);//alsao can use snd_pcm_hw_params_alloca(&hwparams)
  418. )
  419. {
  420. success=false;
  421. hw_params=NULL;
  422. cout<<"Set hw params error error code="<<snd_strerror(error)<<endl;
  423. }
  424. }
  425.  
  426. if(success)
  427. {
  428. //Fill params with a full configuration space for a PCM. initialize the hardware parameter
  429. error=snd_pcm_hw_params_any(*phandler,hw_params);
  430. )
  431. {
  432. success=false;
  433. cout<<"Broken configuration for PCM: no configurations available: "<<snd_strerror(error)<<endl;
  434. }
  435. }
  436.  
  437. if(success)
  438. {
  439. // set the access type
  440. error = snd_pcm_hw_params_set_access(*phandler, hw_params, palsaCfg->accessType);
  441. )
  442. {
  443. cout<<"[SG]Fail to set access type. Reason: "<<snd_strerror(error)<<endl;
  444. success = false;
  445. }
  446. }
  447.  
  448. if(success)
  449. {
  450. switch (palsaCfg->bitsPerSample)
  451. {
  452. case BITS_PER_SAMPLE_8:
  453. {
  454. format = SND_PCM_FORMAT_U8;
  455. break;
  456. }
  457. case BITS_PER_SAMPLE_16:
  458. {
  459. format = SND_PCM_FORMAT_S16_LE; //indicate this was little endian
  460. break;
  461. }
  462. case BITS_PER_SAMPLE_32:
  463. {
  464. format = SND_PCM_FORMAT_S32_LE;
  465. break;
  466. }
  467. default:
  468. {
  469. format = SND_PCM_FORMAT_S16_LE;
  470. cout<<"Invalid format"<<endl;
  471. success=false;
  472. }
  473. }
  474.  
  475. if(success)
  476. {
  477. error=snd_pcm_hw_params_set_format(*phandler,hw_params,format);
  478. )
  479. {
  480. cout<<"set format not available for "<<snd_strerror(error)<<endl;
  481. success=false;
  482. }
  483. }
  484.  
  485. }
  486.  
  487. if(success)
  488. {
  489. error=snd_pcm_hw_params_set_rate_near(*phandler,hw_params,&palsaCfg->samplingFrequency,);
  490. )
  491. {
  492. cout<<"set rate not available for "<<snd_strerror(error)<<endl;
  493. success=false;
  494. }
  495. }
  496.  
  497. if(success)
  498. {
  499. error=snd_pcm_hw_params_set_channels(*phandler,hw_params,palsaCfg->numOfChannels);
  500. )
  501. {
  502. cout<<"set_channels not available for "<<snd_strerror(error)<<endl;
  503. success=false;
  504. }
  505. }
  506. if (success)
  507. {
  508. // set period size (period size is also a chunk size for reading from ALSA)
  509. snd_pcm_uframes_t alsaPeriodFrame = static_cast<snd_pcm_uframes_t>(palsaCfg->alsaPeriodFrame); // One frame could be 4 bytes at most
  510.  
  511. // set period size
  512. error = snd_pcm_hw_params_set_period_size_near(*phandler, hw_params, &alsaPeriodFrame, &dir);
  513. )
  514. {
  515. cout<<"[SG]Fail to set period size. Reason: "<<snd_strerror(error)<<endl;
  516. success = false;
  517. }
  518. }
  519.  
  520. if (success)
  521. {
  522. // set hardware parameters
  523. error = snd_pcm_hw_params(*phandler, hw_params);
  524. )
  525. {
  526. cout<<"[SG]Fail to set hardware parameter. Reason: "<<snd_strerror(error)<<endl;
  527. success = false;
  528. }
  529. }
  530.  
  531. if (success)
  532. {
  533. error=snd_pcm_hw_params_get_period_size(hw_params, &g_frames, &dir); //get frame
  534. cout<<"Frame is "<<g_frames<<endl;
  535.  
  536. // free the memory for hardware parameter structure
  537. snd_pcm_hw_params_free(hw_params);
  538. hw_params = NULL;
  539. // Prepare ALSA device
  540. error = snd_pcm_prepare(*phandler);
  541. )
  542. {
  543. cout<<"Fail to prepare ALSA device. Reason: "<<(snd_strerror(error))<<endl;
  544. success = false;
  545. }
  546. }
  547.  
  548. if (success)
  549. {
  550. cout<<"ALSA device is ready to use"<<endl;
  551. }
  552. else
  553. {
  554. // fail to prepare ALSA device ==> un-initialize ALSA device
  555. if (hw_params != NULL)
  556. {
  557. snd_pcm_hw_params_free(hw_params);
  558. hw_params = NULL;
  559. }
  560. closeAlsaDevice(phandler);
  561. }
  562.  
  563. }
  564. return success;
  565. }
  566.  
  567. bool closeAlsaDevice(snd_pcm_t** phandler)
  568. {
  569. bool ret = true;
  570. snd_pcm_state_t state;
  571. int snd_ret;
  572.  
  573. if (*phandler != NULL)
  574. {
  575. // drop the pending audio frame if needed
  576. state = snd_pcm_state(*phandler);
  577. cout<<"Alsa handler sate: "<<state<<endl;
  578.  
  579. if ((SND_PCM_STATE_RUNNING == state) || (SND_PCM_STATE_XRUN == state) || (SND_PCM_STATE_SUSPENDED == state))
  580. {
  581. snd_ret = snd_pcm_drop(*phandler);
  582. )
  583. {
  584. cout<<"Fail to drop ALSA device. Reason: "<<(snd_strerror(snd_ret))<<endl;
  585. }
  586. }
  587. // close ALSA handler
  588. snd_ret = snd_pcm_close(*phandler);
  589. )
  590. {
  591. cout<<"Fail to close ALSA device. Reason: "<<(snd_strerror(snd_ret))<<endl;
  592. ret = false;
  593. }
  594. *phandler = NULL;
  595. cout<<"CLOSE ALSA DEVICE"<<endl;
  596. }
  597. return ret;
  598.  
  599. }
  600.  
  601. int main()
  602. {
  603. bool ret=false;
  604. snd_pcm_t* m_phandler=NULL;
  605. Alsa_Conf* m_palsaCfg=new Alsa_Conf();
  606. m_palsaCfg->alsaDevice = string("sd_out_16k");
  607. //m_palsaCfg->samplingFrequency = 16000;
  608. m_palsaCfg->alsaCapturePeriod = ;
  609. //m_palsaCfg->numOfChannels = NUM_OF_CHANNELS_1;
  610. m_palsaCfg->block = true; //block
  611. m_palsaCfg->friendlyName = "AlsaWave";
  612. //m_palsaCfg->bitsPerSample = BITS_PER_SAMPLE_16;
  613. m_palsaCfg->alsaPeriodFrame = m_palsaCfg->samplingFrequency * m_palsaCfg->alsaCapturePeriod / ; // calculate the number of frame in one period
  614. m_palsaCfg->alsaBufferSize = m_palsaCfg->alsaPeriodFrame * ; //means the whole buffer was perdion*8, e.g. 10ms means every 10ms we will get/send the data
  615. m_palsaCfg->accessType = SND_PCM_ACCESS_RW_INTERLEAVED;
  616. m_palsaCfg->streamType = SND_PCM_STREAM_PLAYBACK;
  617.  
  618. FILE* fp=NULL;
  619. const string wavePath="/mnt/hgfs/0_SharedFolder/0_Local_Test_Folder/01_TestFolder/TestALSA/left_1k_right_400hz.wav";
  620. //parse the wave file
  621. ret=ParseWaveFile(wavePath,m_palsaCfg,&fp);
  622. //update the value
  623. m_palsaCfg->alsaPeriodFrame = m_palsaCfg->samplingFrequency * m_palsaCfg->alsaCapturePeriod / ; // calculate the number of frame in one period
  624.  
  625. if(ret)
  626. {
  627. //open alsa device
  628. ret=PrepareAlsaDevice(m_palsaCfg,&m_phandler);
  629. }
  630.  
  631. if(ret)
  632. {
  633. PlayWave(&fp,&m_phandler,m_palsaCfg);
  634. }
  635.  
  636. closeAlsaDevice(&m_phandler);
  637. if(fp!=NULL)
  638. {
  639. fclose(fp);
  640. fp=NULL;
  641. }
  642. delete m_palsaCfg;
  643. m_palsaCfg=NULL;
  644.  
  645. ;
  646.  
  647. }

Alsa 读取wave文件,并播放wave 文件的更多相关文章

  1. 读取SD卡文件夹下的MP3文件和播放MP3文件

    首先获取SD卡path路径下的所有的MP3文件,并将文件名和文件大小存入List数组(此代码定义在FileUtils类中): /** * 读取目录中的Mp3文件的名字和大小 */ public Lis ...

  2. Linux音频编程--使用ALSA库播放wav文件

    在UBUNTU系统上使用alsa库完成了对外播放的wav文件的案例. 案例代码: /** *test.c * *注意:这个例子在Ubuntu 12.04.1环境下编译运行成功. * */ #inclu ...

  3. Opencv 播放mp4文件和读取摄像头图以及可能会发生的一些异常问题解决方法

    学习内容 学习Opencv 读取并播放本地视频和打开摄像头图像以及可能会发生的一些异常问题解决方法 代码演示 电脑环境信息: OpenCV版本:4.5.2 ,vs2017 1.视频文件读取与播放 加载 ...

  4. python 播放 wav 文件

    未使用其他库, 只是使用 pywin32 调用系统底层 API 播放 wav 文件. # Our raison d'etre - playing sounds import pywintypes im ...

  5. 【转】C# 视频监控系列(12):H264播放器——播放录像文件

    原文地址:http://www.cnblogs.com/over140/archive/2009/03/23/1419643.html?spm=5176.100239.blogcont51182.16 ...

  6. VC++中MCI播放音频文件 【转】

    MCI播放mp3音频文件例程 源文件中需要包含头文件 Mmsystem.h,在Project->Settings->Link->Object/libray module中加入库 Wi ...

  7. 如何播放 WAV 文件?

    from http://www.vckbase.com/index.php/wv/434 平时,你在多媒体软件的设计中是怎样处理声音文件的呢?使用Windows 提供的API函数 sndPlaySou ...

  8. ffmpeg和opencv 播放视频文件和显示器

    ffmpeg它是基于最新版本,在官网下载http://ffmpeg.zeranoe.com/builds/.编译时VS2010配置相关头文件及库的路径就可以.opencv的搭建參考上一个博客. 首先简 ...

  9. STM32音乐播放器,文件查找的实现

    使用FATFS只是完成了一个基本的文件读写,有时候我们需要扩展一些功能,比如MP3实验,需要上一曲下一曲的切换,扩展的代码如下 //显示目录下所有文件 u8 ShowFileList(u8* dirP ...

  10. Qt 播放音频文件

    Qt播放音频文件的方法有好多中,简单介绍几种 不过一下几种方式都需要在Qt工程文件中添加 QT       += multimedia 第一 QMediaPlayer类 可以播放MP3文件,同时使用也 ...

随机推荐

  1. iOS开发之JSON & XML

    1.概述 JSON (1) 作为一种轻量级的数据交换格式,正在逐步取代XML,成为网络数据的通用格式 (2) 基于JavaScript的一个子集 (3) 易读性略差,编码手写难度大,数据量小 (4) ...

  2. 在TFS中通过程序动态创建Bug并感知Bug解决状态

    为便于跟踪问题解决情况,预警引擎产生的比较严重的预警日志,需要在TFS中登记Bug,通过TFS的状态流转,利用TFS Bug的Web挂钩功能,动态感知Bug解决状态,从而跟踪预警问题的解决状态, 整体 ...

  3. SVN使用小记

    SVN(Subversion)是优秀的版本控制工具,之前在eclipse里面项目管理的时候,File-->Import-->SVN-->从SVN检出项目-->创建新的资源库位置 ...

  4. Sass实战 sass官网

    Sass实战 sass官网 1.相关视频教程:http://pan.baidu.com/s/1eSl8bUa 1.1我的项目源码:http://pan.baidu.com/s/1dFmqbyp 1.2 ...

  5. 安全性测试之防范 DDoS 攻击

    安全性测试之防范 DDoS 攻击   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:90882 ...

  6. 老李分享:Uber究竟是用什么开发语言?

    poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-845052 ...

  7. emmet(快速开发)的使用

    emmet可以帮助您快速编写HTML和CSS代码,从而加速Web前端开发. 比如<html>.<head>.<body>等,现在你只需要1秒钟就可以输入这些标签. ...

  8. ConcurrentHashMap总结

    线程不安全的HashMap 因为多线程环境下,使用HashMap进行put操作会引起死循环,导致CPU利用率接近100%,所以在并发情况下不能使用HashMap,如以下代码   final HashM ...

  9. Spring Dubbo 开发笔记

    第一节:概述 Spring-Dubbo 是我自己写的一个基于spring-boot和dubbo,目的是使用Spring boot的风格来使用dubbo.(即可以了解Spring boot的启动过程又可 ...

  10. dubbo+zipkin调用链监控

    分布式环境下,对于线上出现问题往往比单体应用要复杂的多,原因是前端的一个请求可能对应后端多个系统的多个请求,错综复杂. 对于快速问题定位,我们一般希望是这样的: 从下到下关键节点的日志,入参,出差,异 ...