Giter VIP home page Giter VIP logo

Comments (13)

dreamlayers avatar dreamlayers commented on May 24, 2024 3

This is very annoying in Linux. If I'm running a music visualization program I'll probably want to run it on the sound being played by the computer, not line in. But SDL makes that impossible without editing and recompiling!

First, SDL will ignore PulseAudio sources which are monitors: https://github.com/spurious/SDL-mirror/blob/cc7a10af3465de5d452a7f3d263ee1f36eeaed71/src/audio/pulseaudio/SDL_pulseaudio.c#L680

Second, SDL will set the DONT_MOVE flag if an audio source name is specified, so you can't move the input to a different source: https://github.com/spurious/SDL-mirror/blob/cc7a10af3465de5d452a7f3d263ee1f36eeaed71/src/audio/pulseaudio/SDL_pulseaudio.c#L632
(pavucontrol will offer you GUI elements for doing the move but not actually move. pactl will unhelpfully say "Failure: Invalid argument".)

Right now I edited the SDL_OpenAudioDevice call to make the audio source name NULL, allowing the source to be moved to the monitor.

Switching to an ALSA driver via SDL_AUDIODRIVER=alsa in the environment doesn't help either. For some reason the pulse_monitor source defined in ~/.asoundrc isn't seen by SDL.

from projectm.

spyderboy92 avatar spyderboy92 commented on May 24, 2024

Hey, am a new guy, never made any PR, can you assist me.

from projectm.

spyderboy92 avatar spyderboy92 commented on May 24, 2024

Or provide me direction. Thanks

from projectm.

revmischa avatar revmischa commented on May 24, 2024

Sure... you can come chat in #projectM on freenode IRC if you want
There is some code already for selecting the input device, it needs to be improved.
Read the SDL2 docs for audio input capture

SDL_AudioDeviceID projectMSDL::selectAudioInput(int _count) {
    // ask the user which capture device to use
    // printf("Please select which audio input to use:\n");
    printf("Detected devices:\n");
    for (int i = 0; i < _count; i++) {
        printf("  %i: 🎤%s\n", i, SDL_GetAudioDeviceName(i, true));
    }

    return 0;
}

int projectMSDL::openAudioInput() {
    // get audio driver name (static)
    const char* driver_name = SDL_GetCurrentAudioDriver();
    SDL_Log("Using audio driver: %s\n", driver_name);

    // get audio input device
    unsigned int i, count2 = SDL_GetNumAudioDevices(true);  // capture, please
    if (count2 == 0) {
        SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "No audio capture devices found");
        SDL_Quit();
    }
    for (i = 0; i < count2; i++) {
        SDL_Log("Found audio capture device %d: %s", i, SDL_GetAudioDeviceName(i, true));
    }

    SDL_AudioDeviceID selectedAudioDevice = 0;  // device to open
    if (count2 > 1) {
        // need to choose which input device to use
	selectedAudioDevice = selectAudioInput(count2);
	if (selectedAudioDevice > count2) {
            SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "No audio input device specified.");
            SDL_Quit();
        }
    }

    // params for audio input
    SDL_AudioSpec want, have;

    // requested format
    SDL_zero(want);
    want.freq = 48000;
    want.format = AUDIO_F32;  // float
    want.channels = 2;
    want.samples = 512;
    want.callback = projectMSDL::audioInputCallbackF32;
    want.userdata = this;

    audioDeviceID = SDL_OpenAudioDevice(SDL_GetAudioDeviceName(selectedAudioDevice, true), true, &want, &have, 0);

    if (audioDeviceID == 0) {
        SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Failed to open audio capture device: %s", SDL_GetError());
        SDL_Quit();
    }

    // read characteristics of opened capture device
    SDL_Log("Opened audio capture device %i: %s", audioDeviceID, SDL_GetAudioDeviceName(selectedAudioDevice, true));
    SDL_Log("Sample rate: %i, frequency: %i, channels: %i, format: %i", have.samples, have.freq, have.channels, have.format);
    audioChannelsCount = have.channels;
    audioSampleRate = have.freq;
    audioSampleCount = have.samples;
    audioFormat = have.format;
    audioInputDevice = audioDeviceID;
    return 1;
}

is the code in pmSDL.cpp to find the available devices and select them
something more user-friendly would be nice. not sure what.

from projectm.

spyderboy92 avatar spyderboy92 commented on May 24, 2024

Lots of thanks for assisting me.

from projectm.

revmischa avatar revmischa commented on May 24, 2024
SDL_AudioDeviceID projectMSDL::selectAudioInput(int _count) {
    // ask the user which capture device to use
    // printf("Please select which audio input to use:\n");
    printf("Detected devices:\n");
    for (int i = 0; i < _count; i++) {
        printf("  %i: 🎤%s\n", i, SDL_GetAudioDeviceName(i, true));
    }

    return 0;
}

This should return the index of the desired device

from projectm.

ICShelly76 avatar ICShelly76 commented on May 24, 2024

ProjectX should allow u to lock in the songs with the effects that u choose when swiped left or right etc.

from projectm.

labkey-matthewb avatar labkey-matthewb commented on May 24, 2024

Up vote this bug

https://bugzilla.libsdl.org/show_bug.cgi?id=4187

from projectm.

 avatar commented on May 24, 2024

Hi !
I am a beginner and i would like to contribute , can you please guide me ?

from projectm.

kblaschke avatar kblaschke commented on May 24, 2024

SDL moved to GitHub, issue as well: libsdl-org/SDL#2917

from projectm.

icculus avatar icculus commented on May 24, 2024

SDL moved to GitHub, issue as well: libsdl-org/SDL#2917

We just fixed this issue in SDL, which will be in the 2.0.16 release, that we're working on wrapping up right now. If you get a chance, please test the latest in revision control and make sure it meets your needs!

from projectm.

kblaschke avatar kblaschke commented on May 24, 2024

SDL moved to GitHub, issue as well: libsdl-org/SDL#2917

We just fixed this issue in SDL, which will be in the 2.0.16 release, that we're working on wrapping up right now. If you get a chance, please test the latest in revision control and make sure it meets your needs!

Big thanks for fixing it!

Will test it tomorrow or the day after when I'm back home and give feedback whether it worked or not.

from projectm.

kblaschke avatar kblaschke commented on May 24, 2024

Setting the newly added SDL_HINT_AUDIO_INCLUDE_MONITORS hint works perfectly, PR is open.

from projectm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.