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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented stereo audio recording. #1010

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
5 participants
@Foaly
Contributor

Foaly commented Nov 29, 2015

It does what it says 馃槃 Implemening stereo audio recording.

@Foaly

This comment has been minimized.

Show comment
Hide comment
@Foaly

Foaly Nov 29, 2015

Contributor

Thanks, I updated the documentation with your suggestions.

Contributor

Foaly commented Nov 29, 2015

Thanks, I updated the documentation with your suggestions.

@Foaly

This comment has been minimized.

Show comment
Hide comment
@Foaly

Foaly Jan 4, 2016

Contributor

Rebased onto master.
So what's the status on this? Could it be merged into 2.4?

Contributor

Foaly commented Jan 4, 2016

Rebased onto master.
So what's the status on this? Could it be merged into 2.4?

@Foaly

This comment has been minimized.

Show comment
Hide comment
@Foaly

Foaly Jan 17, 2016

Contributor

Ok I implemented your two suggestions.

Contributor

Foaly commented Jan 17, 2016

Ok I implemented your two suggestions.

@mantognini

This comment has been minimized.

Show comment
Hide comment
@mantognini

mantognini Jan 22, 2016

Member

I can't test but looks good to me. 馃憤

Member

mantognini commented Jan 22, 2016

I can't test but looks good to me. 馃憤

@TankOs

This comment has been minimized.

Show comment
Hide comment
@TankOs

TankOs Jan 26, 2016

Member

Thanks a bunch Foaly, nice work. :) I added some comments on documentation things. I haven't yet tested this, otherwise 馃憤

Member

TankOs commented Jan 26, 2016

Thanks a bunch Foaly, nice work. :) I added some comments on documentation things. I haven't yet tested this, otherwise 馃憤

@Foaly

This comment has been minimized.

Show comment
Hide comment
@Foaly

Foaly Feb 2, 2016

Contributor

You're welcome :) Thanks for reviewing everything. I reworked the documentation and the error messages to be less repetative. Should be good to go now!

Contributor

Foaly commented Feb 2, 2016

You're welcome :) Thanks for reviewing everything. I reworked the documentation and the error messages to be less repetative. Should be good to go now!

@Foaly

This comment has been minimized.

Show comment
Hide comment
@Foaly

Foaly Apr 11, 2016

Contributor

What is holding this back?

Contributor

Foaly commented Apr 11, 2016

What is holding this back?

@eXpl0it3r

This comment has been minimized.

Show comment
Hide comment
@eXpl0it3r

eXpl0it3r Apr 11, 2016

Member

Guess it got forgotten among the other issues. 馃槈

Member

eXpl0it3r commented Apr 11, 2016

Guess it got forgotten among the other issues. 馃槈

@eXpl0it3r eXpl0it3r added s:accepted and removed s:undecided labels Apr 11, 2016

@eXpl0it3r eXpl0it3r added this to the 2.4 milestone Apr 11, 2016

@mantognini

This comment has been minimized.

Show comment
Hide comment
@mantognini

mantognini Apr 22, 2016

Member

Two questions:

  • has anyone some hardware to test this? [I don't]
  • if only mono recording hardware is available, what is the expected behaviour of setting the stereo mode? Failure to open the device or fallback to mono?
Member

mantognini commented Apr 22, 2016

Two questions:

  • has anyone some hardware to test this? [I don't]
  • if only mono recording hardware is available, what is the expected behaviour of setting the stereo mode? Failure to open the device or fallback to mono?
@eXpl0it3r

This comment has been minimized.

Show comment
Hide comment
@eXpl0it3r

eXpl0it3r Apr 22, 2016

Member

I just wrote a little test application:

#include <SFML/Audio.hpp>
#include <iostream>

int main()
{
    if (!sf::SoundBufferRecorder::isAvailable())
    {
        std::cerr << "No recording device availalbe!\n";
        return 1;
    }

    auto recorders = sf::SoundRecorder::getAvailableDevices();

    for(std::size_t i = 0; i < recorders.size(); ++i)
    {
        std::cout << (i + 1) << "\t" << recorders[i] << "\n";
    }

    std::size_t option = 0;

    while(option <= 0 || option > recorders.size())
    {
        std::cout << "Pick your recording device: ";
        std::cin >> option;
    }
    std::cin.ignore();

    sf::SoundBufferRecorder recorder;
    recorder.setDevice(recorders[option - 1]);

    option = 0;

    while(option <= 0 || option > 3)
    {
        std::cout << "Do you want to record Mono (1) or Stereo (2): ";
        std::cin >> option;
    }
    std::cin.ignore();

    recorder.setChannelCount(option);

    std::cout << "Channel count is: " << recorder.getChannelCount() << "\n";

    std::cout << "Press ENTER to start...";
    std::cin.ignore();
    recorder.start();

    std::cout << "Press ENTER to stop...";
    std::cin.ignore();
    recorder.stop();

    std::cout << "Recording stopped!\n";

    sf::SoundBuffer buffer = recorder.getBuffer();

    std::cout << "Recording properties:\n";
    std::cout << "\tSample Count:\t" << buffer.getSampleCount() << "\n";
    std::cout << "\tSample Rate:\t" << buffer.getSampleRate() << "\n";
    std::cout << "\tChannel Count:\t" << buffer.getChannelCount() << "\n";
    std::cout << "\tDuration:\t" << buffer.getDuration().asSeconds() << "s\n";

    sf::Sound sound(buffer);
    sound.play();

    std::cout << "Playing it back...\n";

    while(sound.getStatus() == sf::Sound::Playing)
    {
        sf::sleep(sf::seconds(0.5f));
    }

    char choice = 0;

    while(choice != 'y' && choice != 'Y' && choice != 'n' && choice != 'N')
    {
        std::cout << "Do you want to save it to file (y/n): ";
        std::cin >> choice;
    }
    std::cin.ignore();

    if(choice == 'y' || choice == 'Y')
    {
        buffer.saveToFile("buffer.wav");
    }

    std::cout << "Good Bye!\n";
    std::cout << "Press ENTER to exit...";
    std::cin.ignore();
}

I tested it with my stereo microphone (Zoom H2) and my mono headset microphone (G930). The stereo sound really gets picked up as stereo sound.

Now the interesting part is, that you can also select "stereo" for my headset, but all you get is really just a mirrored mono buffer. Now I'm not sure if this is because the mic is actually stereo, or if Windows just pretends it is stereo or if OpenAL pretends it can record stereo from it.

One thing that I miss from the API right now, is to check what channel counts a microphone supports.

Member

eXpl0it3r commented Apr 22, 2016

I just wrote a little test application:

#include <SFML/Audio.hpp>
#include <iostream>

int main()
{
    if (!sf::SoundBufferRecorder::isAvailable())
    {
        std::cerr << "No recording device availalbe!\n";
        return 1;
    }

    auto recorders = sf::SoundRecorder::getAvailableDevices();

    for(std::size_t i = 0; i < recorders.size(); ++i)
    {
        std::cout << (i + 1) << "\t" << recorders[i] << "\n";
    }

    std::size_t option = 0;

    while(option <= 0 || option > recorders.size())
    {
        std::cout << "Pick your recording device: ";
        std::cin >> option;
    }
    std::cin.ignore();

    sf::SoundBufferRecorder recorder;
    recorder.setDevice(recorders[option - 1]);

    option = 0;

    while(option <= 0 || option > 3)
    {
        std::cout << "Do you want to record Mono (1) or Stereo (2): ";
        std::cin >> option;
    }
    std::cin.ignore();

    recorder.setChannelCount(option);

    std::cout << "Channel count is: " << recorder.getChannelCount() << "\n";

    std::cout << "Press ENTER to start...";
    std::cin.ignore();
    recorder.start();

    std::cout << "Press ENTER to stop...";
    std::cin.ignore();
    recorder.stop();

    std::cout << "Recording stopped!\n";

    sf::SoundBuffer buffer = recorder.getBuffer();

    std::cout << "Recording properties:\n";
    std::cout << "\tSample Count:\t" << buffer.getSampleCount() << "\n";
    std::cout << "\tSample Rate:\t" << buffer.getSampleRate() << "\n";
    std::cout << "\tChannel Count:\t" << buffer.getChannelCount() << "\n";
    std::cout << "\tDuration:\t" << buffer.getDuration().asSeconds() << "s\n";

    sf::Sound sound(buffer);
    sound.play();

    std::cout << "Playing it back...\n";

    while(sound.getStatus() == sf::Sound::Playing)
    {
        sf::sleep(sf::seconds(0.5f));
    }

    char choice = 0;

    while(choice != 'y' && choice != 'Y' && choice != 'n' && choice != 'N')
    {
        std::cout << "Do you want to save it to file (y/n): ";
        std::cin >> choice;
    }
    std::cin.ignore();

    if(choice == 'y' || choice == 'Y')
    {
        buffer.saveToFile("buffer.wav");
    }

    std::cout << "Good Bye!\n";
    std::cout << "Press ENTER to exit...";
    std::cin.ignore();
}

I tested it with my stereo microphone (Zoom H2) and my mono headset microphone (G930). The stereo sound really gets picked up as stereo sound.

Now the interesting part is, that you can also select "stereo" for my headset, but all you get is really just a mirrored mono buffer. Now I'm not sure if this is because the mic is actually stereo, or if Windows just pretends it is stereo or if OpenAL pretends it can record stereo from it.

One thing that I miss from the API right now, is to check what channel counts a microphone supports.

@eXpl0it3r eXpl0it3r assigned eXpl0it3r and unassigned eXpl0it3r Apr 22, 2016

@Foaly

This comment has been minimized.

Show comment
Hide comment
@Foaly

Foaly Apr 23, 2016

Contributor

Thank you. Sorry for forgetting to share my testing code.
Of course I also tested the code and I get the same results. In my case I used a USB mixer/interface and a simple microphone that plugs into my computer with a simple (mono) jack plug. When I select stereo on the mono device i get a stereo buffer where both channels containing the same signal.
The OpenAL API for getting sound from a microphone is pretty simple. There is no way to test how many channels a sound input device has. When you think about it, it is also only possible for digital devices like USB interfaces, USB Webcam's or USB microphones. For a microphone using an analog Jack plug it's impossible to query the channel count. So I guess it makes sense to fill the second channel with the data from the first one, if stereo is requested on a mono device. Think about what happens when a mono sound (record) is played back on a stereo sound system. I think it's a sensible default from OpenAL. It's not mentioned in any documentation though.

Contributor

Foaly commented Apr 23, 2016

Thank you. Sorry for forgetting to share my testing code.
Of course I also tested the code and I get the same results. In my case I used a USB mixer/interface and a simple microphone that plugs into my computer with a simple (mono) jack plug. When I select stereo on the mono device i get a stereo buffer where both channels containing the same signal.
The OpenAL API for getting sound from a microphone is pretty simple. There is no way to test how many channels a sound input device has. When you think about it, it is also only possible for digital devices like USB interfaces, USB Webcam's or USB microphones. For a microphone using an analog Jack plug it's impossible to query the channel count. So I guess it makes sense to fill the second channel with the data from the first one, if stereo is requested on a mono device. Think about what happens when a mono sound (record) is played back on a stereo sound system. I think it's a sensible default from OpenAL. It's not mentioned in any documentation though.

@eXpl0it3r

This comment has been minimized.

Show comment
Hide comment
@eXpl0it3r

eXpl0it3r May 4, 2016

Member

Sounds good to me. Does anyone have any further comments on this? Anyone want to test (especially on OS X and Linux)?

Member

eXpl0it3r commented May 4, 2016

Sounds good to me. Does anyone have any further comments on this? Anyone want to test (especially on OS X and Linux)?

@eXpl0it3r eXpl0it3r self-assigned this May 4, 2016

@eXpl0it3r

This comment has been minimized.

Show comment
Hide comment
@eXpl0it3r

eXpl0it3r May 6, 2016

Member

This PR has been added to my merge list, meaning it will be merged soon, unless someone raises any concerns.

Member

eXpl0it3r commented May 6, 2016

This PR has been added to my merge list, meaning it will be merged soon, unless someone raises any concerns.

@eXpl0it3r

This comment has been minimized.

Show comment
Hide comment
@eXpl0it3r

eXpl0it3r May 8, 2016

Member

Merged in f49c156

Member

eXpl0it3r commented May 8, 2016

Merged in f49c156

@eXpl0it3r eXpl0it3r closed this May 8, 2016

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