Code Monkey home page Code Monkey logo

Comments (9)

tumtumtum avatar tumtumtum commented on July 27, 2024

Oh iOS it is recommended to use the MPVolumeView to allow users to control the volume. If you need programmatic control of the volume control for mixing or whatever reason then that's currently outside the scope of this project.

from streamingkit.

xieweizhi avatar xieweizhi commented on July 27, 2024

oh,i see .I have solved this problem by using MPVolumeView.thanks :)

from streamingkit.

jalmaas avatar jalmaas commented on July 27, 2024

For OS X?

from streamingkit.

tumtumtum avatar tumtumtum commented on July 27, 2024

StreamingKit doesn't have inbuilt volume control (you can see from the API). I'm happy to take pull requests. If you want to add it yourself, there's thousands of pages on the internet about how to do it. Even adding using STKAudioPlayer.appendFrameFilter to change the volume by adjusting the amplitude of the frames wouldn't take very long.

from streamingkit.

jalmaas avatar jalmaas commented on July 27, 2024

Thanks! A framefilter worked for me. First take on implementation if others need it:

__weak __typeof(self)wself = self;

[self.stkAudioPlayer addFrameFilterWithName:@"Volume" afterFilterWithName:nil block:^(UInt32 channelsPerFrame, UInt32 bytesPerFrame, UInt32 frameCount, void *frames) {
        float volume = wself.volume;

        SInt16* samples16 = (SInt16*)frames;
        SInt32* samples32 = (SInt32*)frames;

        if (bytesPerFrame / channelsPerFrame == 2)
        {
            for (int i = 0; i < frameCount * channelsPerFrame; i += channelsPerFrame)
            {
                samples16[i] = samples16[i] *volume;
                samples16[i + 1] = samples16[i + 1] *volume;
            }
        }
        else if (bytesPerFrame / channelsPerFrame == 4)
        {
            for (int i = 0; i < frameCount * channelsPerFrame; i += channelsPerFrame) 
            {
                samples32[i] = samples32[i] * volume;
                samples32[i+1] = samples32[i+1] * volume;
            }
        }
        else
        {
            return;
        }
    }];

from streamingkit.

tumtumtum avatar tumtumtum commented on July 27, 2024

I think on Mac (not iOS) you could use this as well...but I haven't tested it:

AudioUnitSetParameter (audioUnit, kHALOutputParam_Volume, kAudioUnitScope_Output, busNumber, volume, 0);

from streamingkit.

tumtumtum avatar tumtumtum commented on July 27, 2024

Thanks for the example code of your solution btw πŸ‘

from streamingkit.

tumtumtum avatar tumtumtum commented on July 27, 2024

Ok I've added volume control support in master via the volume property. On iOS it uses a multi-channel mixer. Since the mixer will add a slight overhead, on iOS volume control won't work unless you pass in the STKAudioPlayerOptionEnableVolumeMixer options when initialising the player.

from streamingkit.

jalmaas avatar jalmaas commented on July 27, 2024

πŸ‘

from streamingkit.

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.