Forum Rule: Always post complete source code & details to reproduce any issue!
Page 5 of 5 FirstFirst ... 3 4 5
Results 101 to 108 of 108

Thread: WaveplayerEx

  1. #101
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,066
    Quote Originally Posted by Frank B View Post
    - If you say at some point that you really want to include it in the official version, I will change the license. But not before.
    Normally I would not even look at source code using an incompatible open source license. Especially for features I plan to eventually implement, just viewing how it was done can influence future work with really should be done independently when the license is incompatible.

    So far I have only looked at the readme as shown on the repository on github, and the license header. I stopped when I saw you used GPL3.

    Most of the features explained in the readme are things I have long wanted to implement in the audio library wav player. Whether I would use the code as implemented, I do not know yet, because I have not even looked at the code.

  2. #102
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,308
    Well, I think that's called "deadlock".

  3. #103
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,308
    Quote Originally Posted by Frank B View Post
    Well, I think that's called "deadlock".
    Ok, I think the player is useful for others, so I'll change to licence for some time to MIT.

    That's OK.
    I'll change it back to GPL if you decide not to use it. But please drop a note.
    Thank you.

  4. #104
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,066
    Yes, I will work with it later this month.

    3 other major audio contributions are also pending. Will probably spend several days to do all 4 together.

    Please be patient. I need you to understand many other important tasks need to be done, including minor PCB design changes for 3 Teensy models due to chip shortages on the diodes and voltage regulators (we just recently managed to buy the alternate parts).

  5. #105
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,308
    Quote Originally Posted by Frank B View Post
    - Yesterday I noticed that pause() does not work correctly with multiple files.
    I think it works now. Wasn't that easy

    Please report any remaining bugs as issue @ github. Thank you!

  6. #106
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,308
    @Paul, I'm adding a "loop" feature. Please give me a few days.


    Other question: Can we use the existing "Resampler.cpp" to adapt to different samplerates?

  7. #107
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,308
    Quote Originally Posted by Frank B View Post
    @Paul, I'm adding a "loop" feature. Please give me a few days.


    Other question: Can we use the existing "Resampler.cpp" to adapt to different samplerates?
    Ok... had too much time today...
    Some new functions:

    size_t position(); - returns the current sample number. Will increase in steps of 128 (or AUDIO_BLOCK_SAMPLES)
    bool setPosition(size_t sample); works only in paused mode - sets the start position for pause(false).
    void loop(bool enable); - loops the whole file. Call it for an already playing or paused file. Will loop endless, until you call stop() or pause()
    void loop(size_t firstSample, size_t lastSample, uint16_t count); - number of first sample, last sample, count of repeats. If lastSample = 0 it uses the last sample in the file.
    int loopCount(void);- returns the count of remaining loops.

    The details are sometimes not as easy as it may sound... I will describe loop() in detail, later.

  8. #108
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    9,308
    Ok, let's assume we use the Nums_7dot1_8_44100.wav file from the examples. There is a voice, counting from 1 to 8 (each number on a different channel - but this is not interesting here)

    There is a gap of exactly one second between the numbers.

    1.
    Code:
    playWav.play("Nums_7dot1_8_44100.wav");
    Plays the whole file, one time.

    2.
    Code:
    playWav.play("Nums_7dot1_8_44100.wav");
    playWav.loop(true);
    Repeats the whole file until your ears bleed.

    3.
    Code:
    playWav.play("Nums_7dot1_8_44100.wav", true);
    playWav.setPosition(44100 * 5);
    playWav.pause(false);
    Starts in paused mode, sets the position to second 5, then un-pauses.


    4.
    Code:
    playWav.play("Nums_7dot1_8_44100.wav");
    playWav.loop(0, 0, -1);
    Same as 2.

    5.
    Code:
    playWav.play("Nums_7dot1_8_44100.wav");
    playWav.loop(0, 0, 0);
    Does noot loop (loop-count is zero)

    6.
    Code:
    playWav.play("Nums_7dot1_8_44100.wav");
    playWav.loop(0, 0, -1);
    delay(20000);
    playWav.loop(0, 0, 0);
    Like 5 - stopps looping after 20 seconds. The files plays to the end! Only the loop gets disabled.

    7.
    Now, the tricky parts:
    Code:
    playWav.play("Nums_7dot1_8_44100.wav");
    for (int i=7; i>0; i--) {
        playWav.loop(44100 * i, 44100 * (i + 1), 1);
        while ( playWav.loopCount() > 0 ) {;}
    }
    Well.. you'll hear:
    "1 2 3 4 5 6 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8"
    - the while waits until the looping is finished.
    - it does _not_ stop or pause then, instead it plays the file to the end. IF there is no new loop, pause or stop command.

    8.
    Code:
    playWav.play("Nums_7dot1_8_44100.wav");
      delay(5000);
      playWav.loop(0, 44100 * 3, 2);
    You'll hear:
    1 2 3 4 1 2 1 2 1 2 3 4 5 6 7 8
    -> it counts up to 4 because of the delay.
    -> after that the loop gets startet. Teensy detects that it already playing behind the stop marker of the loop and rewinds to the first sample.

    Important: It does not detect that immedeately. This happens when it trys to read the next block of data from them media.
    If you need exact timing, you need to define the loop _before_ the stop marker is reached.
    What means "before". Hm, that#s tricky. Rule of thumb: As early as possible. It has to happen before it reads the datablock where the end-sample is located.
    The size of the datablocks is variable, and depends on the number playWav (and record) objects and the AUDIO_BLOCK_SIZE.
    Just give it enough millisconds and try it out.
    Last edited by Frank B; Today at 12:38 PM.

Posting Permissions

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