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

Add mixer.Channel.set_source_location() #1844

Merged
merged 12 commits into from
Jun 5, 2023

Conversation

yunline
Copy link
Contributor

@yunline yunline commented Feb 13, 2023

def set_source_location(self, angle:float, distance:float) -> None: ...

Example:

import pygame
import time

pygame.init()
pygame.mixer.init()

snd=pygame.mixer.Sound("你吼那么大声干什么嘛.mp3")

ch=snd.play(loops=10)
angle=0
distance=50 # distance from 0 to 255
while ch.get_busy():
    ch.set_source_location(angle,distance)
    angle+=1
    angle%=360
    time.sleep(0.005)

You should hear the sound running around you.

docs/reST/ref/mixer.rst Outdated Show resolved Hide resolved
@MyreMylar
Copy link
Member

We could perhaps have an interactive test here

@MyreMylar MyreMylar closed this Feb 13, 2023
@MyreMylar MyreMylar reopened this Feb 13, 2023
@MyreMylar MyreMylar closed this Feb 13, 2023
@MyreMylar MyreMylar reopened this Feb 13, 2023
@MyreMylar MyreMylar requested a review from a team as a code owner February 13, 2023 22:01
@MightyJosip MightyJosip added mixer pygame.mixer New API This pull request may need extra debate as it adds a new class or function to pygame labels Feb 14, 2023
Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

New test works great!

@MyreMylar MyreMylar added this to the 2.2 milestone Mar 2, 2023
@Starbuck5 Starbuck5 modified the milestones: 2.2, 2.3 Mar 26, 2023
@Starbuck5
Copy link
Member

Starbuck5 commented Jun 1, 2023

I assumed from the title of this PR that this was a way to set the playback time of a channel. I.e. rewind or seek forward to a time.

I'm quite excited to see it's actually about setting the direction of a sound effect. That could be a super cool effect!

However I'm wondering if we can get a more clear name than set_position to illustrate the functionality. Maybe set_direction or something like set_playback_angle? Just throwing out ideas, what do you think?

docs/reST/ref/mixer.rst Outdated Show resolved Hide resolved
test/mixer_test.py Outdated Show resolved Hide resolved
@MyreMylar
Copy link
Member

I assumed from the title of this PR that this was a way to set the playback time of a channel. I.e. rewind or seek forward to a time.

I'm quite excited to see it's actually about setting the direction of a sound effect. That could be a super cool effect!

However I'm wondering if we can get a more clear name than set_position to illustrate the functionality. Maybe set_direction or something like set_playback_angle? Just throwing out ideas, what do you think?

I believe this is usually called positional audio. Looking elsewhere OpenAL uses a concept of audio sources for its positional audio implementation - perhaps we could go with something like set_source_location() which may be both somewhat familiar to users of OpenAL, cover both direction and angle, and also unique/intriguing enough that other users read the docs to figure out exactly what it does. @Starbuck5 is correct that we are already using the function name set_pos() in mixer.music to refer to setting the time position in the music file.

@yunline
Copy link
Contributor Author

yunline commented Jun 1, 2023

This function should support float input

@yunline yunline changed the title Add mixer.Channel.set_position() Add mixer.Channel.set_source_location() Jun 1, 2023
Copy link
Member

@Starbuck5 Starbuck5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Starbuck5 Starbuck5 merged commit c172028 into pygame-community:main Jun 5, 2023
29 checks passed
@yunline yunline deleted the sound-position branch June 5, 2023 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mixer pygame.mixer New API This pull request may need extra debate as it adds a new class or function to pygame
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants