Team Riedel - display
Dependencies: LCD_fonts SPI_TFT_ILI9341 CMSIS_DSP_401_without_cm4 mbed-src SDFileSystem wavfile
audio_if.cpp@13:ab0285338951, 2015-12-14 (annotated)
- Committer:
- linx0576
- Date:
- Mon Dec 14 22:13:11 2015 +0000
- Revision:
- 13:ab0285338951
- Parent:
- 10:0986108f8aa3
update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EricLew | 9:5a860b9c8a6a | 1 | /** |
EricLew | 9:5a860b9c8a6a | 2 | ****************************************************************************** |
EricLew | 9:5a860b9c8a6a | 3 | * @file /Src/audio_if.c |
EricLew | 9:5a860b9c8a6a | 4 | * @author Central Labs |
EricLew | 9:5a860b9c8a6a | 5 | * @version V1.0.0 |
EricLew | 9:5a860b9c8a6a | 6 | * @date 7-May-2015 |
EricLew | 9:5a860b9c8a6a | 7 | * @brief USB Device Audio interface file. |
EricLew | 9:5a860b9c8a6a | 8 | ****************************************************************************** |
EricLew | 9:5a860b9c8a6a | 9 | @attention |
EricLew | 9:5a860b9c8a6a | 10 | * |
EricLew | 9:5a860b9c8a6a | 11 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
EricLew | 9:5a860b9c8a6a | 12 | * |
EricLew | 9:5a860b9c8a6a | 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
EricLew | 9:5a860b9c8a6a | 14 | * You may not use this file except in compliance with the License. |
EricLew | 9:5a860b9c8a6a | 15 | * You may obtain a copy of the License at: |
EricLew | 9:5a860b9c8a6a | 16 | * |
EricLew | 9:5a860b9c8a6a | 17 | * http://www.st.com/software_license_agreement_liberty_v2 |
EricLew | 9:5a860b9c8a6a | 18 | * |
EricLew | 9:5a860b9c8a6a | 19 | * Redistribution and use in source and binary forms, with or without modification, |
EricLew | 9:5a860b9c8a6a | 20 | * are permitted provided that the following conditions are met: |
EricLew | 9:5a860b9c8a6a | 21 | * 1. Redistributions of source code must retain the above copyright notice, |
EricLew | 9:5a860b9c8a6a | 22 | * this list of conditions and the following disclaimer. |
EricLew | 9:5a860b9c8a6a | 23 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
EricLew | 9:5a860b9c8a6a | 24 | * this list of conditions and the following disclaimer in the documentation |
EricLew | 9:5a860b9c8a6a | 25 | * and/or other materials provided with the distribution. |
EricLew | 9:5a860b9c8a6a | 26 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
EricLew | 9:5a860b9c8a6a | 27 | * may be used to endorse or promote products derived from this software |
EricLew | 9:5a860b9c8a6a | 28 | * without specific prior written permission. |
EricLew | 9:5a860b9c8a6a | 29 | * |
EricLew | 9:5a860b9c8a6a | 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
EricLew | 9:5a860b9c8a6a | 31 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
EricLew | 9:5a860b9c8a6a | 32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
EricLew | 9:5a860b9c8a6a | 33 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
EricLew | 9:5a860b9c8a6a | 34 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
EricLew | 9:5a860b9c8a6a | 35 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
EricLew | 9:5a860b9c8a6a | 36 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
EricLew | 9:5a860b9c8a6a | 37 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
EricLew | 9:5a860b9c8a6a | 38 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
EricLew | 9:5a860b9c8a6a | 39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
EricLew | 9:5a860b9c8a6a | 40 | * |
EricLew | 9:5a860b9c8a6a | 41 | ****************************************************************************** |
EricLew | 9:5a860b9c8a6a | 42 | */ |
EricLew | 9:5a860b9c8a6a | 43 | |
EricLew | 9:5a860b9c8a6a | 44 | /* Includes ------------------------------------------------------------------*/ |
EricLew | 9:5a860b9c8a6a | 45 | #include "audio_if.h" |
EricLew | 9:5a860b9c8a6a | 46 | |
EricLew | 9:5a860b9c8a6a | 47 | //uint16_t PDM_Buffer[AUDIO_CHANNELS*AUDIO_SAMPLING_FREQUENCY/1000*64/8]; |
EricLew | 9:5a860b9c8a6a | 48 | //static uint16_t PCM_Buffer[AUDIO_CHANNELS*AUDIO_SAMPLING_FREQUENCY/1000]; |
EricLew | 9:5a860b9c8a6a | 49 | |
EricLew | 9:5a860b9c8a6a | 50 | /* Private typedef -----------------------------------------------------------*/ |
EricLew | 9:5a860b9c8a6a | 51 | /* Private define ------------------------------------------------------------*/ |
EricLew | 9:5a860b9c8a6a | 52 | /* Private macro -------------------------------------------------------------*/ |
EricLew | 9:5a860b9c8a6a | 53 | /* Private function prototypes -----------------------------------------------*/ |
EricLew | 9:5a860b9c8a6a | 54 | /* Private variables ---------------------------------------------------------*/ |
EricLew | 9:5a860b9c8a6a | 55 | |
EricLew | 9:5a860b9c8a6a | 56 | |
EricLew | 9:5a860b9c8a6a | 57 | /* Private functions ---------------------------------------------------------*/ |
EricLew | 9:5a860b9c8a6a | 58 | /* This table maps the audio device class setting in 1/256 dB to a |
EricLew | 9:5a860b9c8a6a | 59 | * linear 0-64 scaling used in pdm_filter.c. It is computed as |
EricLew | 9:5a860b9c8a6a | 60 | * 256*20*log10(index/64). */ |
EricLew | 9:5a860b9c8a6a | 61 | //const int16_t vol_table[65] = |
EricLew | 9:5a860b9c8a6a | 62 | //{ 0x8000, 0xDBE0, 0xE1E6, 0xE56B, 0xE7EB, 0xE9DB, 0xEB70, 0xECC7, |
EricLew | 9:5a860b9c8a6a | 63 | //0xEDF0, 0xEEF6, 0xEFE0, 0xF0B4, 0xF176, 0xF228, 0xF2CD, 0xF366, |
EricLew | 9:5a860b9c8a6a | 64 | //0xF3F5, 0xF47C, 0xF4FB, 0xF574, 0xF5E6, 0xF652, 0xF6BA, 0xF71C, |
EricLew | 9:5a860b9c8a6a | 65 | //0xF778, 0xF7D6, 0xF82D, 0xF881, 0xF8D2, 0xF920, 0xF96B, 0xF9B4, |
EricLew | 9:5a860b9c8a6a | 66 | //0xF9FB, 0xFA3F, 0xFA82, 0xFAC2, 0xFB01, 0xFB3E, 0xFB79, 0xFBB3, |
EricLew | 9:5a860b9c8a6a | 67 | //0xFBEB, 0xFC22, 0xFC57, 0xFC8C, 0xFCBF, 0xFCF1, 0xFD22, 0xFD51, |
EricLew | 9:5a860b9c8a6a | 68 | //0xFD80, 0xFDAE, 0xFDDB, 0xFE07, 0xFE32, 0xFE5D, 0xFE86, 0xFEAF, |
EricLew | 9:5a860b9c8a6a | 69 | //0xFED7, 0xFF00, 0xFF25, 0xFF4B, 0xFF70, 0xFF95, 0xFFB9, 0xFFD0, |
EricLew | 9:5a860b9c8a6a | 70 | //0x0000 }; |
EricLew | 9:5a860b9c8a6a | 71 | |
EricLew | 9:5a860b9c8a6a | 72 | //volatile uint8_t VolumeSetting=64; |
EricLew | 9:5a860b9c8a6a | 73 | |
EricLew | 9:5a860b9c8a6a | 74 | /** |
EricLew | 9:5a860b9c8a6a | 75 | * @brief Initializes the AUDIO media low layer. |
EricLew | 9:5a860b9c8a6a | 76 | * @param AudioFreq: Audio frequency used to play the audio stream. |
EricLew | 9:5a860b9c8a6a | 77 | * @param BitRes: desired bit resolution |
EricLew | 9:5a860b9c8a6a | 78 | * @param ChnlNbr: number of channel to be configured |
EricLew | 9:5a860b9c8a6a | 79 | * @retval AUDIO_OK in case of success, AUDIO_ERROR otherwise |
EricLew | 9:5a860b9c8a6a | 80 | */ |
EricLew | 9:5a860b9c8a6a | 81 | int8_t Audio_Init(void) |
EricLew | 9:5a860b9c8a6a | 82 | { |
EricLew | 9:5a860b9c8a6a | 83 | return BSP_AUDIO_IN_Init(48000, 16, 1); |
linx0576 | 10:0986108f8aa3 | 84 | |
EricLew | 9:5a860b9c8a6a | 85 | } |
EricLew | 9:5a860b9c8a6a | 86 | |
EricLew | 9:5a860b9c8a6a | 87 | |
EricLew | 9:5a860b9c8a6a | 88 | |
EricLew | 9:5a860b9c8a6a | 89 | /** |
EricLew | 9:5a860b9c8a6a | 90 | * @brief Start audio recording engine |
EricLew | 9:5a860b9c8a6a | 91 | * @retval AUDIO_OK in case of success, AUDIO_ERROR otherwise |
EricLew | 9:5a860b9c8a6a | 92 | */ |
EricLew | 9:5a860b9c8a6a | 93 | int8_t Audio_Record(uint16_t * recbuff) |
EricLew | 9:5a860b9c8a6a | 94 | { |
EricLew | 9:5a860b9c8a6a | 95 | int8_t res = BSP_AUDIO_IN_Record(recbuff, 2048); |
EricLew | 9:5a860b9c8a6a | 96 | // AudioProcess(pbuf, recbuff); |
EricLew | 9:5a860b9c8a6a | 97 | return res; |
EricLew | 9:5a860b9c8a6a | 98 | } |
EricLew | 9:5a860b9c8a6a | 99 | |
EricLew | 9:5a860b9c8a6a | 100 | /** |
EricLew | 9:5a860b9c8a6a | 101 | * @brief Controls AUDIO Volume. |
EricLew | 9:5a860b9c8a6a | 102 | * @param vol: Volume level |
EricLew | 9:5a860b9c8a6a | 103 | * @retval AUDIO_OK in case of success, AUDIO_ERROR otherwise |
EricLew | 9:5a860b9c8a6a | 104 | */ |
EricLew | 9:5a860b9c8a6a | 105 | //int8_t Audio_VolumeCtl(int16_t Volume) |
EricLew | 9:5a860b9c8a6a | 106 | //{ |
EricLew | 9:5a860b9c8a6a | 107 | // /* Call low layer volume setting function */ |
EricLew | 9:5a860b9c8a6a | 108 | // int j; |
EricLew | 9:5a860b9c8a6a | 109 | // |
EricLew | 9:5a860b9c8a6a | 110 | // j = 0; |
EricLew | 9:5a860b9c8a6a | 111 | // /* Find the setting nearest to the desired setting */ |
EricLew | 9:5a860b9c8a6a | 112 | // while(j<64 && |
EricLew | 9:5a860b9c8a6a | 113 | // abs(Volume-vol_table[j]) > abs(Volume-vol_table[j+1])) { |
EricLew | 9:5a860b9c8a6a | 114 | // j++; |
EricLew | 9:5a860b9c8a6a | 115 | // } |
EricLew | 9:5a860b9c8a6a | 116 | // /* Now do the volume adjustment */ |
EricLew | 9:5a860b9c8a6a | 117 | // VolumeSetting = (uint8_t)j; |
EricLew | 9:5a860b9c8a6a | 118 | // return BSP_AUDIO_IN_SetVolume(VolumeSetting); |
EricLew | 9:5a860b9c8a6a | 119 | // |
EricLew | 9:5a860b9c8a6a | 120 | // |
EricLew | 9:5a860b9c8a6a | 121 | //} |
EricLew | 9:5a860b9c8a6a | 122 | |
EricLew | 9:5a860b9c8a6a | 123 | /** |
EricLew | 9:5a860b9c8a6a | 124 | * @brief Controls AUDIO Mute. |
EricLew | 9:5a860b9c8a6a | 125 | * @param cmd: Command opcode |
EricLew | 9:5a860b9c8a6a | 126 | * @retval AUDIO_OK in case of success, AUDIO_ERROR otherwise |
EricLew | 9:5a860b9c8a6a | 127 | */ |
EricLew | 9:5a860b9c8a6a | 128 | //int8_t Audio_MuteCtl(uint8_t cmd) |
EricLew | 9:5a860b9c8a6a | 129 | //{ |
EricLew | 9:5a860b9c8a6a | 130 | // return AUDIO_OK; |
EricLew | 9:5a860b9c8a6a | 131 | //} |
EricLew | 9:5a860b9c8a6a | 132 | |
EricLew | 9:5a860b9c8a6a | 133 | |
EricLew | 9:5a860b9c8a6a | 134 | /** |
EricLew | 9:5a860b9c8a6a | 135 | * @brief Stops audio acquisition |
EricLew | 9:5a860b9c8a6a | 136 | * @param none |
EricLew | 9:5a860b9c8a6a | 137 | * @retval AUDIO_OK in case of success, AUDIO_ERROR otherwise |
EricLew | 9:5a860b9c8a6a | 138 | */ |
EricLew | 9:5a860b9c8a6a | 139 | int8_t Audio_Stop(void) |
EricLew | 9:5a860b9c8a6a | 140 | { |
EricLew | 9:5a860b9c8a6a | 141 | return BSP_AUDIO_IN_Stop(); |
EricLew | 9:5a860b9c8a6a | 142 | |
EricLew | 9:5a860b9c8a6a | 143 | } |
EricLew | 9:5a860b9c8a6a | 144 | |
EricLew | 9:5a860b9c8a6a | 145 | /** |
EricLew | 9:5a860b9c8a6a | 146 | * @brief Pauses audio acquisition |
EricLew | 9:5a860b9c8a6a | 147 | * @param none |
EricLew | 9:5a860b9c8a6a | 148 | * @retval AUDIO_OK in case of success, AUDIO_ERROR otherwise |
EricLew | 9:5a860b9c8a6a | 149 | */ |
EricLew | 9:5a860b9c8a6a | 150 | // |
EricLew | 9:5a860b9c8a6a | 151 | //int8_t Audio_Pause(void) |
EricLew | 9:5a860b9c8a6a | 152 | //{ |
EricLew | 9:5a860b9c8a6a | 153 | // return 0; |
EricLew | 9:5a860b9c8a6a | 154 | //} |
EricLew | 9:5a860b9c8a6a | 155 | |
EricLew | 9:5a860b9c8a6a | 156 | |
EricLew | 9:5a860b9c8a6a | 157 | /** |
EricLew | 9:5a860b9c8a6a | 158 | * @brief Resumes audio acquisition |
EricLew | 9:5a860b9c8a6a | 159 | * @param none |
EricLew | 9:5a860b9c8a6a | 160 | * @retval AUDIO_OK in case of success, AUDIO_ERROR otherwise |
EricLew | 9:5a860b9c8a6a | 161 | */ |
EricLew | 9:5a860b9c8a6a | 162 | //int8_t Audio_Resume(void) |
EricLew | 9:5a860b9c8a6a | 163 | //{ |
EricLew | 9:5a860b9c8a6a | 164 | // return AUDIO_OK; |
EricLew | 9:5a860b9c8a6a | 165 | //} |
EricLew | 9:5a860b9c8a6a | 166 | |
EricLew | 9:5a860b9c8a6a | 167 | /** |
EricLew | 9:5a860b9c8a6a | 168 | * @brief Manages command from usb |
EricLew | 9:5a860b9c8a6a | 169 | * @param None |
EricLew | 9:5a860b9c8a6a | 170 | * @retval AUDIO_OK in case of success, AUDIO_ERROR otherwise |
EricLew | 9:5a860b9c8a6a | 171 | */ |
EricLew | 9:5a860b9c8a6a | 172 | // |
EricLew | 9:5a860b9c8a6a | 173 | //int8_t Audio_CommandMgr(uint8_t cmd) |
EricLew | 9:5a860b9c8a6a | 174 | //{ |
EricLew | 9:5a860b9c8a6a | 175 | // return AUDIO_OK; |
EricLew | 9:5a860b9c8a6a | 176 | //} |
EricLew | 9:5a860b9c8a6a | 177 | // |
EricLew | 9:5a860b9c8a6a | 178 | //void AudioProcess(uint16_t * pbuf, uint16_t * recbuff) |
EricLew | 9:5a860b9c8a6a | 179 | //{ |
EricLew | 9:5a860b9c8a6a | 180 | // BSP_AUDIO_IN_PDMToPCM(pbuf,recbuff); |
EricLew | 9:5a860b9c8a6a | 181 | // // need to copy recbuff to final output buff (in chunks) |
EricLew | 9:5a860b9c8a6a | 182 | //} |
EricLew | 9:5a860b9c8a6a | 183 | |
EricLew | 9:5a860b9c8a6a | 184 | void PrintData(uint16_t * recbuff) |
EricLew | 9:5a860b9c8a6a | 185 | { |
EricLew | 9:5a860b9c8a6a | 186 | for (int i=0; i < AUDIO_CHANNELS*AUDIO_SAMPLING_FREQUENCY/1000; ++i) { |
EricLew | 9:5a860b9c8a6a | 187 | if (!(i%10)) |
EricLew | 9:5a860b9c8a6a | 188 | pc.printf("\r\n\t"); |
EricLew | 9:5a860b9c8a6a | 189 | pc.printf("%d ", recbuff[i]); |
EricLew | 9:5a860b9c8a6a | 190 | } |
EricLew | 9:5a860b9c8a6a | 191 | pc.printf("\r\n\r\n"); |
EricLew | 9:5a860b9c8a6a | 192 | } |
EricLew | 9:5a860b9c8a6a | 193 | |
EricLew | 9:5a860b9c8a6a | 194 | void WriteData(uint16_t * recbuff) |
EricLew | 9:5a860b9c8a6a | 195 | { |
EricLew | 9:5a860b9c8a6a | 196 | |
EricLew | 9:5a860b9c8a6a | 197 | //Try to mount the SD card |
EricLew | 9:5a860b9c8a6a | 198 | pc.printf("Mounting SD card..."); |
EricLew | 9:5a860b9c8a6a | 199 | if (sd.mount() != 0) { |
EricLew | 9:5a860b9c8a6a | 200 | pc.printf("failed!\r\n"); |
EricLew | 9:5a860b9c8a6a | 201 | return; |
EricLew | 9:5a860b9c8a6a | 202 | } |
EricLew | 9:5a860b9c8a6a | 203 | pc.printf("mounted successfully!\r\n"); |
EricLew | 9:5a860b9c8a6a | 204 | |
EricLew | 9:5a860b9c8a6a | 205 | // write event to log |
EricLew | 9:5a860b9c8a6a | 206 | FILE *fp = fopen("/sd/event_log.txt", "a"); |
EricLew | 9:5a860b9c8a6a | 207 | if (fp != NULL) { |
EricLew | 9:5a860b9c8a6a | 208 | for (int i=0; i < AUDIO_CHANNELS*AUDIO_SAMPLING_FREQUENCY/1000; ++i) { |
EricLew | 9:5a860b9c8a6a | 209 | if (!(i%10)) |
EricLew | 9:5a860b9c8a6a | 210 | fprintf(fp, "\r\n"); |
EricLew | 9:5a860b9c8a6a | 211 | fprintf(fp, "%d ", recbuff[i]); |
EricLew | 9:5a860b9c8a6a | 212 | } |
EricLew | 9:5a860b9c8a6a | 213 | fprintf(fp, "\r\n\r\n"); |
EricLew | 9:5a860b9c8a6a | 214 | fprintf(fp, "Woohoo! I made a file!\r\n"); |
EricLew | 9:5a860b9c8a6a | 215 | fclose(fp); |
EricLew | 9:5a860b9c8a6a | 216 | PrintData(recbuff); |
EricLew | 9:5a860b9c8a6a | 217 | pc.printf("success!\r\n"); |
EricLew | 9:5a860b9c8a6a | 218 | } else { |
EricLew | 9:5a860b9c8a6a | 219 | pc.printf("failed!\r\n"); |
EricLew | 9:5a860b9c8a6a | 220 | } |
EricLew | 9:5a860b9c8a6a | 221 | |
EricLew | 9:5a860b9c8a6a | 222 | pc.printf("creating WAV file"); |
EricLew | 9:5a860b9c8a6a | 223 | static const char *target_filename = "/sd/rec-test.wav"; |
EricLew | 9:5a860b9c8a6a | 224 | rec(target_filename, recbuff, 48); |
EricLew | 9:5a860b9c8a6a | 225 | |
EricLew | 9:5a860b9c8a6a | 226 | |
EricLew | 9:5a860b9c8a6a | 227 | sd.unmount(); |
EricLew | 9:5a860b9c8a6a | 228 | pc.printf("sd card unmounted\r\n\r\n"); |
EricLew | 9:5a860b9c8a6a | 229 | |
EricLew | 9:5a860b9c8a6a | 230 | } |
EricLew | 9:5a860b9c8a6a | 231 | |
EricLew | 9:5a860b9c8a6a | 232 | #define WAVFILE_ERROR_PRINT(RESULT) \ |
EricLew | 9:5a860b9c8a6a | 233 | do { \ |
EricLew | 9:5a860b9c8a6a | 234 | WavFileResult R = RESULT; \ |
EricLew | 9:5a860b9c8a6a | 235 | if (R != WavFileResultOK) { \ |
EricLew | 9:5a860b9c8a6a | 236 | char wavfile_error_print_text[BUFSIZ]; \ |
EricLew | 9:5a860b9c8a6a | 237 | wavfile_result_string(R, wavfile_error_print_text, sizeof(wavfile_error_print_text)); \ |
EricLew | 9:5a860b9c8a6a | 238 | printf("%s (code=%d)\r\n", wavfile_error_print_text, R); \ |
EricLew | 9:5a860b9c8a6a | 239 | return 1; \ |
EricLew | 9:5a860b9c8a6a | 240 | } \ |
EricLew | 9:5a860b9c8a6a | 241 | } while(0) |
EricLew | 9:5a860b9c8a6a | 242 | |
EricLew | 9:5a860b9c8a6a | 243 | int rec(const char *filename, uint16_t * recbuff, uint16_t size) |
EricLew | 9:5a860b9c8a6a | 244 | { |
EricLew | 9:5a860b9c8a6a | 245 | WavFileResult result; |
EricLew | 9:5a860b9c8a6a | 246 | wavfile_info_t info; |
EricLew | 9:5a860b9c8a6a | 247 | wavfile_data_t data; |
EricLew | 9:5a860b9c8a6a | 248 | |
EricLew | 9:5a860b9c8a6a | 249 | WAVFILE_INFO_AUDIO_FORMAT(&info) = 1; |
EricLew | 9:5a860b9c8a6a | 250 | WAVFILE_INFO_NUM_CHANNELS(&info) = 1; |
EricLew | 9:5a860b9c8a6a | 251 | WAVFILE_INFO_SAMPLE_RATE(&info) = 1000; |
EricLew | 9:5a860b9c8a6a | 252 | WAVFILE_INFO_BYTE_RATE(&info) = 2000; |
EricLew | 9:5a860b9c8a6a | 253 | WAVFILE_INFO_BLOCK_ALIGN(&info) = 2; |
EricLew | 9:5a860b9c8a6a | 254 | WAVFILE_INFO_BITS_PER_SAMPLE(&info) = 16; |
EricLew | 9:5a860b9c8a6a | 255 | |
EricLew | 9:5a860b9c8a6a | 256 | WAVFILE *wf = wavfile_open(filename, WavFileModeWrite, &result); |
EricLew | 9:5a860b9c8a6a | 257 | WAVFILE_ERROR_PRINT(result); |
EricLew | 9:5a860b9c8a6a | 258 | WAVFILE_ERROR_PRINT(wavfile_write_info(wf, &info)); |
EricLew | 9:5a860b9c8a6a | 259 | |
EricLew | 9:5a860b9c8a6a | 260 | pc.printf("[REC:%s]\r\n", filename); |
EricLew | 9:5a860b9c8a6a | 261 | pc.printf("\tWAVFILE_INFO_AUDIO_FORMAT(&info) = %d\r\n", WAVFILE_INFO_AUDIO_FORMAT(&info)); |
EricLew | 9:5a860b9c8a6a | 262 | pc.printf("\tWAVFILE_INFO_NUM_CHANNELS(&info) = %d\r\n", WAVFILE_INFO_NUM_CHANNELS(&info)); |
EricLew | 9:5a860b9c8a6a | 263 | pc.printf("\tWAVFILE_INFO_SAMPLE_RATE(&info) = %d\r\n", WAVFILE_INFO_SAMPLE_RATE(&info)); |
EricLew | 9:5a860b9c8a6a | 264 | pc.printf("\tWAVFILE_INFO_BYTE_RATE(&info) = %d\r\n", WAVFILE_INFO_BYTE_RATE(&info)); |
EricLew | 9:5a860b9c8a6a | 265 | pc.printf("\tWAVFILE_INFO_BLOCK_ALIGN(&info) = %d\r\n", WAVFILE_INFO_BLOCK_ALIGN(&info)); |
EricLew | 9:5a860b9c8a6a | 266 | pc.printf("\tWAVFILE_INFO_BITS_PER_SAMPLE(&info) = %d\r\n", WAVFILE_INFO_BITS_PER_SAMPLE(&info)); |
EricLew | 9:5a860b9c8a6a | 267 | |
EricLew | 9:5a860b9c8a6a | 268 | // const int interval_us = 1000000 / WAVFILE_INFO_SAMPLE_RATE(&info); |
EricLew | 9:5a860b9c8a6a | 269 | |
EricLew | 9:5a860b9c8a6a | 270 | int dropout = 0; |
EricLew | 9:5a860b9c8a6a | 271 | // unsigned int count = 0; |
EricLew | 9:5a860b9c8a6a | 272 | WAVFILE_DATA_NUM_CHANNELS(&data) = 1; |
EricLew | 9:5a860b9c8a6a | 273 | // for (int i=0; i<size; ++i) { |
EricLew | 9:5a860b9c8a6a | 274 | // WAVFILE_DATA_CHANNEL_DATA(&data, 0) = 0; //buffer[rp]; |
EricLew | 9:5a860b9c8a6a | 275 | // WAVFILE_ERROR_PRINT(wavfile_write_data(wf, &data)); |
EricLew | 9:5a860b9c8a6a | 276 | WAVFILE_ERROR_PRINT(wavfile_write_data_bulk_uint16(wf, recbuff, AUDIO_CHANNELS, size)); |
EricLew | 9:5a860b9c8a6a | 277 | // } |
EricLew | 9:5a860b9c8a6a | 278 | |
EricLew | 9:5a860b9c8a6a | 279 | pc.printf("\t-- Rec done. (dropout=%d) --\r\n", dropout); |
EricLew | 9:5a860b9c8a6a | 280 | |
EricLew | 9:5a860b9c8a6a | 281 | WAVFILE_ERROR_PRINT(wavfile_close(wf)); |
EricLew | 9:5a860b9c8a6a | 282 | return 0; |
EricLew | 9:5a860b9c8a6a | 283 | } |
EricLew | 9:5a860b9c8a6a | 284 | |
EricLew | 9:5a860b9c8a6a | 285 | |
EricLew | 9:5a860b9c8a6a | 286 | |
EricLew | 9:5a860b9c8a6a | 287 | |
EricLew | 9:5a860b9c8a6a | 288 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
EricLew | 9:5a860b9c8a6a | 289 |