Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamRecording::duration is wrong #443

Open
martinwork opened this issue Aug 26, 2024 · 1 comment · May be fixed by lancaster-university/codal-core#172
Open

StreamRecording::duration is wrong #443

martinwork opened this issue Aug 26, 2024 · 1 comment · May be fixed by lancaster-university/codal-core#172

Comments

@martinwork
Copy link
Collaborator

The second float cast is in the wrong place.
https://github.com/lancaster-university/codal-core/blob/509086cc8590465041b15493ab52b56e7071c110/source/streams/StreamRecording.cpp#L65

@martinwork
Copy link
Collaborator Author

martinwork commented Aug 29, 2024

Created PR lancaster-university/codal-core#172

With the test below... before the change

Recording length:   11098 bytes
Recording rate:     11000 Hz
Recording duration: 672 ms

After the change

Recording length:   11036 bytes
Recording rate:     11000 Hz
Recording duration: 1003 ms
test code

#include "MicroBit.h"
#include "StreamRecording.h"
#include "SerialStreamer.h"

MicroBit uBit;

int main() {
    uBit.init();

    static SplitterChannel *splitterChannel = uBit.audio.splitter->createChannel();

    splitterChannel->requestSampleRate(11000);

    static StreamRecording *recording = new StreamRecording(*splitterChannel);

    static MixerChannel *mixerChannel = uBit.audio.mixer.addChannel(*recording, recording->getSampleRate());

    static SerialStreamer *streamer = new SerialStreamer(*recording, SERIAL_STREAM_MODE_DECIMAL);

    MicroBitAudio::requestActivation();
    mixerChannel->setVolume(75.0);
    uBit.audio.mixer.setVolume(1023);

    uBit.serial.printf("Recording rate: %d\n", (int)recording->getSampleRate());
    uBit.serial.printf("Mixer rate: %d\n", (int)uBit.audio.mixer.getSampleRate());

    while (true) {
        if (uBit.buttonA.isPressed()) {
            uBit.sleep(500);

            uBit.display.print("R");
            recording->recordAsync();
            uBit.sleep(1000);
            recording->stop();
            uBit.serial.printf("Recording length:   %d bytes\n", (int) recording->length());
            uBit.serial.printf("Recording rate:     %d Hz\n", (int) recording->getSampleRate());
            uBit.serial.printf("Recording duration: %d ms\n", (int) ( 1000 * recording->duration( recording->getSampleRate())));
        } else if (uBit.buttonB.isPressed()) {
            uBit.display.print("P");
            recording->connect(*mixerChannel);
            recording->play();
        } else if (uBit.logo.isPressed()) {
            recording->connect(*streamer);
            recording->play();
        }
        uBit.display.clear();
        uBit.sleep(100);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants