55namespace daisy
66{
77/* * Audio Recording Module
8- **
9- ** Record audio into a working buffer that is gradually written to a WAV file on an SD Card.
108 **
11- ** Recordings are made with floating point input, and will be converted to the
12- ** specified bits per sample internally
9+ ** Record audio into a working buffer that is gradually written to a WAV file on an SD Card.
10+ **
11+ ** Recordings are made with floating point input, and will be converted to the
12+ ** specified bits per sample internally
1313 **
1414 ** For now only 16-bit and 32-bit (signed int) formats are supported
1515 ** f32 and s24 formats will be added next
@@ -18,7 +18,7 @@ namespace daisy
1818 ** effect on the performance of the streaming behavior of the WavWriter.
1919 ** Memory use can be calculated as: (2 * transfer_size) bytes
2020 ** Performance optimal with sizes: 16384, 32768
21- **
21+ **
2222 ** To use:
2323 ** 1. Create a WavWriter<size> object (e.g. WavWriter<32768> writer)
2424 ** 2. Configure the settings as desired by creating a WavWriter<32768>::Config struct and setting the settings.
@@ -27,7 +27,7 @@ namespace daisy
2727 ** 5. Write to it within your audio callback using: writer.Sample(value)
2828 ** 6. Fill the Wav File on the SD Card with data from your main loop by running: writer.Write()
2929 ** 7. When finished with the recording finalize, and close the file with: writer.SaveFile();
30- **
30+ **
3131 ** */
3232template <size_t transfer_size>
3333class WavWriter
@@ -52,7 +52,7 @@ class WavWriter
5252 int32_t bitspersample;
5353 };
5454
55- /* * State of the internal Writing mechanism.
55+ /* * State of the internal Writing mechanism.
5656 ** When the buffer is a certain amount full one section will write its contents
5757 ** while the other is still being written to. This is performed circularly
5858 ** so that audio will be uninterrupted during writing. */
@@ -87,12 +87,12 @@ class WavWriter
8787 }
8888
8989 /* * Records the current sample into the working buffer,
90- ** queues writes to media when necessary.
91- **
90+ ** queues writes to media when necessary.
91+ **
9292 ** \param in should be a pointer to an array of samples */
9393 void Sample (const float *in)
9494 {
95- for (size_t i = 0 ; i < cfg_.channels ; i++)
95+ for (int i = 0 ; i < cfg_.channels ; i++)
9696 {
9797 switch (cfg_.bitspersample )
9898 {
@@ -145,28 +145,28 @@ class WavWriter
145145 recording_ = false ;
146146
147147 // Flush remaining data in the transfer buffer
148- if (wptr_ > 0 ) // Check if there is unwritten data in the buffer
148+ if (wptr_ > 0 ) // Check if there is unwritten data in the buffer
149149 {
150150 uint32_t remaining_size = wptr_ * (cfg_.bitspersample / 8 );
151151 // Ensure remaining_size does not exceed the buffer size
152- if (remaining_size > sizeof (transfer_buff))
152+ if (remaining_size > sizeof (transfer_buff))
153153 {
154154 remaining_size = sizeof (transfer_buff);
155155 }
156156 f_write (&fp_, transfer_buff, remaining_size, &bw);
157157 }
158-
158+
159159 wavheader_.FileSize = CalcFileSize ();
160160 f_lseek (&fp_, 0 );
161161 f_write (&fp_, &wavheader_, sizeof (wavheader_), &bw);
162162 f_close (&fp_);
163163
164164 // Clear the transfer buffer and reset the buffer state
165165 memset (transfer_buff, 0 , sizeof (transfer_buff));
166- bstate_ = BufferState::IDLE;
167- wptr_ = 0 ; // Reset the write pointer
168- num_samps_ = 0 ; // Reset the number of samples
169- recording_ = false ; // Ensure recording is inactive
166+ bstate_ = BufferState::IDLE;
167+ wptr_ = 0 ; // Reset the write pointer
168+ num_samps_ = 0 ; // Reset the number of samples
169+ recording_ = false ; // Ensure recording is inactive
170170 }
171171
172172 /* * Opens a file for writing. Writes the initial WAV Header, and gets ready for stream-based recording. */
0 commit comments