Skip to content

Commit eddb0ce

Browse files
Merge pull request #71 from marcel-licence/update_documentation
Create teensy.md
2 parents 05606ab + 9a958e7 commit eddb0ce

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

extras/audio.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Audio Codec Interface with Microcontroller
2+
3+
This project demonstrates how to set up and interface an audio codec with a microcontroller using I2S communication. It covers the necessary signal connections, configuration options, and a test signal mode for validation.
4+
5+
## Getting Started
6+
7+
### Overview of Audio Codec Signals
8+
9+
When interfacing an audio codec with a microcontroller, several key signals are involved:
10+
11+
- **BCLK (Bit Clock)**: This is the clock signal that synchronizes the data transfer between the microcontroller and the codec. It defines the speed at which bits are transferred.
12+
- **WCLK (Word Clock) / LRCLK (Left-Right Clock)**: This signal specifies the sample rate and is used to separate left and right audio channels.
13+
- **DIN (Data In)**: The data input pin on the codec, where audio data is received from the microcontroller.
14+
- **DOUT (Data Out)**: The data output pin on the microcontroller, where audio data is sent to the codec.
15+
16+
The microcontroller must be configured to use I2S for these signals, ensuring the codec receives the audio data correctly.
17+
18+
### Configuration
19+
20+
The configuration options for this project are specified in `config.h`. Important parameters include:
21+
22+
- **`SAMPLE_RATE`**: Defines the audio sampling rate.
23+
- **`SAMPLE_BUFFER_SIZE`**: Determines the buffer size for audio data. This impacts the generated test frequency if enabled.
24+
25+
To test your setup, you can enable a saw wave test signal by defining `OUTPUT_SAW_TEST` in `config.h`. This test signal will output a saw wave with a frequency calculated as:
26+
27+
```c
28+
Frequency = SAMPLE_RATE / SAMPLE_BUFFER_SIZE
29+
```
30+
31+
Example:
32+
```c
33+
#define OUTPUT_SAW_TEST // Uncomment to enable the saw wave test signal
34+
```
35+
36+
### Codec-Specific Considerations
37+
38+
Some codecs may require additional configuration:
39+
40+
- **I2S Configuration**: Most audio codecs can be configured over I2S. Ensure that your microcontroller's I2S settings (bit depth, sample rate, etc.) are compatible with the codec's specifications.
41+
- **Additional Pins**: Certain codecs, such as the PCM5201a, may have additional pins like a *Mute* pin. Refer to the codec-specific documentation [PCM5102a](ml_pcm5102a.md) for details on these configurations.
42+
43+
### Running the Project
44+
45+
1. **Flash the Firmware**: Program the microcontroller with the provided firmware.
46+
2. **Check Serial Monitor**: After starting the firmware, open the serial monitor. The monitor will display the pin settings for the I2S interface, allowing you to verify correct signal connections and configuration.
47+
48+
## Contributing and Support
49+
50+
For questions, feedback, or further assistance, feel free to start a discussion on the GitHub repository.
51+
52+
Happy coding!

extras/teensy.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# ML_SynthTools Library with Teensy
2+
3+
This guide explains how to use the `ML_SynthTools` library with the Teensy board, including necessary modifications to ensure proper functionality. Follow the steps below to integrate and configure everything correctly.
4+
5+
## Required Changes to Teensy Setup
6+
7+
To use `ML_SynthTools` with the Teensy, there are a few modifications that need to be made to the Teensy core files. These changes adjust linker flags and audio settings for compatibility with your library.
8+
9+
### 1. Add Linker Flags to `platform.txt`
10+
11+
To configure the correct linker flags, you need to modify the `platform.txt` file for Teensy. This ensures that the necessary libraries are linked correctly.
12+
13+
- Locate the `platform.txt` file in the following directory:
14+
```
15+
%appdata%\..\Local\Arduino15\packages\teensy\hardware\avr\1.59.0\platform.txt
16+
```
17+
18+
- Open the file in a text editor, and add the following line under the section for `compiler.libraries.ldflags`:
19+
```
20+
compiler.libraries.ldflags=
21+
```
22+
23+
This will enable the necessary linker flags required by `ML_SynthTools`.
24+
25+
### 2. Modify Audio Stream Header for Block Size and Sample Rate
26+
27+
Next, you need to update some audio settings in the Teensy core to ensure compatibility with the `ML_SynthTools` library.
28+
29+
- Navigate to the following Teensy file:
30+
```
31+
%appdata%\..\Local\Arduino15\packages\teensy\hardware\avr\1.59.0\cores\teensy4\AudioStream.h
32+
```
33+
34+
- Open the file and locate the line:
35+
``` c
36+
#define AUDIO_BLOCK_SAMPLES 128
37+
```
38+
39+
- Change it to:
40+
``` c
41+
#define AUDIO_BLOCK_SAMPLES 48
42+
```
43+
44+
This modification adjusts the number of audio samples in each audio block for better performance with the `ML_SynthTools` library.
45+
46+
- Next, find the line:
47+
``` c
48+
#define AUDIO_SAMPLE_RATE_EXACT 44100.0f
49+
```
50+
51+
- Change it to:
52+
``` c
53+
#define AUDIO_SAMPLE_RATE_EXACT 48000.0f
54+
```
55+
56+
This sets the audio sample rate to 48 kHz, which is required for the correct operation of `ML_SynthTools`.
57+
58+
## Installation Steps
59+
60+
1. **Install Teensyduino:** If you haven't already, make sure to install [Teensyduino](https://www.pjrc.com/teensy/teensyduino.html), which provides the necessary libraries and tools for programming the Teensy board.
61+
62+
2. **Install `ML_SynthTools` Library:**
63+
- Download or clone the `ML_SynthTools` library to your Arduino libraries folder.
64+
- You can also install it via the Arduino Library Manager (if available).
65+
66+
3. **Configure the Teensy Board:**
67+
- In the Arduino IDE, go to **Tools** > **Board** and select your Teensy model.
68+
- Set the correct COM port for the Teensy.
69+
70+
4. **Upload Your Code:**
71+
- Once the above steps are completed, upload your code that uses the `ML_SynthTools` library to your Teensy board.
72+
73+
## Conclusion
74+
75+
After making these changes, you should be able to use the `ML_SynthTools` library with your Teensy board. If you encounter any issues, make sure all modifications are correctly applied and that the Teensy board is properly selected in the Arduino IDE.

0 commit comments

Comments
 (0)