Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: wav2sketch inside Teensyduino

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    13

    wav2sketch inside Teensyduino

    Hello dear forum members,

    i was asking myself earlier today if it is possible to use the wav2sketch.c program "inside" teensyduino? What do I mean with that: Is it possible to use the wav2sketch algorithm WHILE running your program or do I need to convert the .WAV files BEFORE using them inside my code?

    I'm asking that because I want to sample a .WAV file "on the fly" that i'm gonna record e.g. with a synth or a guitar.
    So I do not want to close arduino and extract the samples each and every time I'm making a new record - I want to have it processed inside my teensyduino project - is that possible?

    Has someone tried that before? Sorry if I'm making a superflous thread here but I couldn't find anything via search on that topic!


    With kind regards,
    Mala

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,272
    Just store it on SD? The waveplayer can play wav-files.
    Maybe together with MTP.

    You can record them in RAW format too. Maybe to SD, also. Or to PSRAM, or... wherever.
    If there is no ready to use player, it's not that difficult to write your own.
    Last edited by Frank B; 02-23-2021 at 11:40 AM.

  3. #3
    Junior Member
    Join Date
    Feb 2021
    Posts
    13
    Quote Originally Posted by Frank B View Post
    Just store it on SD? The waveplayer can play wav-files.
    Maybe together with MTP.

    You can record them in RAW format too. Maybe to SD, also. Or to PSRAM, or... wherever.
    If there is no ready to use player, it's not that difficult to write your own.

    Guten Tag Frank,

    i want to write a discrete fourier transformation in teensyduino. The idea is to send discrete values of an audio signal into that function, so i need to sample the .WAV file which I'm recording. But I'd like to do that "on the fly" rather than running wav2sketch for every single recording I'll make. My goal is to connect my synthesizer with the Teensy / Audio Board, play a chord, and get the recording of that chord as a .WAV file which then gets directly converted with wav2sketch.

    So i can summarize my issue as follows: I do not want to open up my terminal and start the wav2sketch EVERY TIME a new recording was made. I'd like to integrate the wav2ksetch inside my program, so that i don't have to convert everything manually - is that possible?

    Thanks for your help y'all!


    With kind regards,
    Mala

  4. #4
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    277
    you could probably do it

    using the code inside:
    https://github.com/PaulStoffregen/Au...lay_sd_wav.cpp

    function:
    AudioPlaySdWav::consume(uint32_t size)

    which takes care of the wav file decoding.

    then store the raw data in SRAM where the playback can be done from.


    Do you want to store the wav file on a sd-card
    or send it to the teensy using USB-serial?

  5. #5
    Junior Member
    Join Date
    Feb 2021
    Posts
    13
    Quote Originally Posted by manicksan View Post
    you could probably do it

    using the code inside:
    https://github.com/PaulStoffregen/Au...lay_sd_wav.cpp

    function:
    AudioPlaySdWav::consume(uint32_t size)

    which takes care of the wav file decoding.

    then store the raw data in SRAM where the playback can be done from.

    Thanks for your answer manicksan!

    The AudioPlaySdWav::consume(uint32_t size) function could really probably work, but i somehow can't really find the encoder segment? I thought it should look like the wav2sketch encoder:

    (taken from: https://raw.githubusercontent.com/Pa...h/wav2sketch.c)

    Code:
    uint8_t ulaw_encode(int16_t audio)
    {
    	uint32_t mag, neg;
    
    	if (audio >= 0) {
    		mag = audio;
    		neg = 0;
    	} else {
    		mag = audio * -1;
    		neg = 0x80;
    	}
    	mag += 128;
    	if (mag > 0x7FFF) mag = 0x7FFF;
    	if (mag >= 0x4000) return neg | 0x70 | ((mag >> 10) & 0x0F);  // 01wx yz00 0000 0000
    	if (mag >= 0x2000) return neg | 0x60 | ((mag >> 9) & 0x0F);   // 001w xyz0 0000 0000
    	if (mag >= 0x1000) return neg | 0x50 | ((mag >> 8) & 0x0F);   // 0001 wxyz 0000 0000
    	if (mag >= 0x0800) return neg | 0x40 | ((mag >> 7) & 0x0F);   // 0000 1wxy z000 0000
    	if (mag >= 0x0400) return neg | 0x30 | ((mag >> 6) & 0x0F);   // 0000 01wx yz00 0000
    	if (mag >= 0x0200) return neg | 0x20 | ((mag >> 5) & 0x0F);   // 0000 001w xyz0 0000
    	if (mag >= 0x0100) return neg | 0x10 | ((mag >> 4) & 0x0F);   // 0000 0001 wxyz 0000
    	                   return neg | 0x00 | ((mag >> 3) & 0x0F);   // 0000 0000 1wxy z000
    }

    If I could combine the AudioPlaySdWav::consume(uint32_t size) function with the encoder above I would be quite a bit further than earlier today, thank you


    Quote Originally Posted by manicksan View Post
    Do you want to store the wav file on a sd-card
    or send it to the teensy using USB-serial?

    I think SD-card would be easier to handle, what do you think?

    Thank you all so much for helping me!


    With kind regards,
    Mala

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •