add sample recording and playback capabilities #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added a new class for creating sample recordings from microphone input, and added sample playback capabilities to CalliopeSoundMotor.
The sample format is optimized for 1-bit output, and allows for efficient data compression at the cost of sound quality. Efficiency depends on the harmonic spectrum of the sample, with higher frequencies generating larger data. On average, 2-3 seconds of human speech can be compressed into 1 KB of sample data at the default sample rate. Sample format is unsigned 8-bit PWM, which is a simple record of the time taken until the next output state change. If a sample byte is 0, then no state change occurs and the next state change is delayed by 256 ticks. Samples are recorded and played back at a rate of 8 KHz by default, this can be changed to up to ~11KHz. At faster rates, correct playback is not ensured.
Both recording and playback are implemented as interrupt services. CPU load will be approx. 85% at 8 KHz, so it is not possible to run other load-heavy tasks in parallel.
Sampling thresholds for recording are tuned to the current board setup, they will need to be adjusted once the planned changes to the board are implemented. Likewise, there will be some minor changes necessary if the piezo is replaced by a true speaker.
This is my first contribution to the Calliope mini project, please be patient with me and let me know about any mistakes. Also note that I have not changed the versioning.