Play sounds

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #14902
    chiomatic
    Participant

    Hello

    I would like to simply play a pure tone, without recording anything.
    So the idea would be to:
    1) have a vector storing the waveform for a given sound frequency (e.g. 5 kHz) and sampling rate (44100 Hz);
    2) have a loop in which a value from that vector is sequentially written using writeDAC

    I haven’t implemented step 1 yet, however I fail with step 2.
    With help from this tutorial https://www.youtube.com/watch?v=-pAYJHW3Js8 , I connected the output of Audio Hacker to A5 and ran the following code, but it does not work.
    Only one value is printed on the serial monitor. If I remove the second for loop and just keep delayMicroseconds, values are constantly and rapidly printed but they do not seem to change according to the i-for-loop, they only fluctuate +-1 and change substantially as I change the volume.

    Any help would be very appreciated!
    Thanks!

    -alessandro

    #include <AudioHacker.h>

    void setup() {
    Serial.begin(115200); // connect to the serial port
    AudioHacker.begin();
    }

    ISR(TIMER1_OVF_vect) {
    for (int i = 0; i = 4095; i++){
    AudioHacker.writeDAC(i);
    int val = analogRead(A5);
    Serial.println(val);
    // Wait 100 ms:
    for (int j = 0; j = 100; j++){
    delayMicroseconds(1000);
    }
    }
    }

    #15064
    darui
    Participant

    Looks workable

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.