-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
feat: Channels for audio playing #417
Comments
This is an interesting idea. It might be good to implement, but I bet you could already do something like this pretty quickly by connecting it to a common gain node, now that #383 is done const K = kaplay({global: false})
const sfxChannel = new GainNode(K.audioContext)
sfxChannel.connect(K.audioContext.destination);
const musicChannel = new GainNode(K.audioContext)
musicChannel.connect(K.audioContext.destination);
// and so on
// to use a channel
K.play("foo", { connectTo: sfxChannel }); only problem is that you aren't able to connect the gain nodes to KAPLAY's master node that way... waiting on #400 for that |
Interesting, i managed to do something with creating custom classes and volumes from gamesaves and etc, but seems like a good approach |
Can't we do that internally while looking for a good way of give people globals? Something simpler like Amy said, but that internally uses your method Would be a great PR |
class AudioChannel {
muted: boolean,
volume: number,
}
function playAudio(opts: audioPlayOpt & { channel: AudioChannel }) {
play({
volume: opts.channel.muted ? 0 : opts.channel.volume
})
} is what im doing right now, i store this channels in a game save so you can set volumes, is this a good API? im not sure |
It'll work for one-off and short sounds, but if you have longer sounds that might have the volume of the channel changed or muted while the sound is playing, it will not update, since the |
const audioPlayObject =play({
volume: opts.channel.muted ? 0 : opts.channel.volume
})
return audioPlayerObject wouldn't this work? you could get the audioPlay object and then modify the pitch |
Well, you'd kind of have to do it manually -- const myChannel: AudioChannel = ...;
const player: AudioPlay = playAudio("boom", { channel: myChannel });
// this doesn't update player.volume
myChannel.volume = ...;
// to change the sound mid-play
player.volume = ...; |
well i'd use channels to manage sound effects volume and music volume sepparetely, idk about you, but changing it sepparetely doesn't look so bad |
Is your feature request related to a problem? Please describe.
Let's say you'd like to have channels like sfx and music to play them on different volumes, that'd be kinda hard since you'd have to write them from zero (which i've done)
Describe the solution you'd like
Something along the lines of
play({
channel: "sfx"
})
This way you can manage different sound volumes
The text was updated successfully, but these errors were encountered: