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

Thread: Create new sample

  1. #1
    Junior Member
    Join Date
    Jul 2019
    Posts
    1

    Create new sample

    Hi guys, I'm trying to create a new sample from a wav file, but i cant do it . Can someone help me with a step by step . Thanks!

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,792
    The PJRC has an Audio Tutorial that cover using wave files, did you find those examples and get them to work with similar code? Please make note of what Teensy and hardware is at hand - the PJRC Audio board or other is in use.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    Quote Originally Posted by cesarcofre View Post
    Can someone help me with a step by step .
    Would you need those steps for Mac, Linux or Windows?

    Generic not-OS-specific version is you put all the WAV files you want into a folder together with the wav2sketch program. There's a pre-built copy for Windows. On Mac & Linux you need to compile it. See the comments at the copy of the code for a typical command line. On Mac, you'll need to install Apple's X-code command line package (free download from Apple's website).

    Then just run wav2sketch from the command line. It will read all the WAV files in that folder and create the files you copy into your Arduino sketch folder. Restart Arduino, so it re-reads your program and sees the new files.

    If you want smaller output, use a program like Audacity to resample the WAV files to 22.1 kHz or even 11.025 kHz. Trim any silent samples off the beginning, and if the clip is long, maybe use the fade out effect to end it sooner and trim away all the unused silence, so you get smaller files.

    By default wav2sketch expects 16 bit samples and uses ulaw compression to encode them with only 8 bits. For simple sounds, ulaw's distortion isn't bad (usually much better than if you just discard the low 8 bits). For complex sounds, like music with multiple instruments, ulaw's distortion can really ruin the sound of the weaker or higher frequency parts. If you give wav2sketch an optional "-16" option on the command line, it will preserve full 16 bit quality. The output is double the size which burns Teensy's internal flash very fast, but if your sound is complex it will sound better.

    For playing sample, click File > Examples > Audio > SamplePlayer. Or check out Part 2-03 of the audio library tutorial. Scroll down for the full walkthrough video, where Alysia & I demo that and every other part of the tutorial.
    Last edited by PaulStoffregen; 07-03-2019 at 12:59 PM.

Tags for this Thread

Posting Permissions

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