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

Generated tone sounds different from other tone generators #30

Open
vycoder opened this issue Dec 31, 2023 · 2 comments
Open

Generated tone sounds different from other tone generators #30

vycoder opened this issue Dec 31, 2023 · 2 comments
Assignees

Comments

@vycoder
Copy link

vycoder commented Dec 31, 2023

I've tried the following

new ZenTone().play(frequency = 200f, volume = 100)
new ZoneTone(encoding = AudioFormat.ENCODING_PCM_32BIT, channelMask = AudioFormat.CHANNEL_OUT_STEREO)

But the resulting sound, doesn't sound like the other tone generators. They all sound like this: (https://www.youtube.com/watch?v=YOnBu8CClmQ)

What am I doing wrong here?

@nisrulz nisrulz self-assigned this Jan 1, 2024
@nisrulz
Copy link
Owner

nisrulz commented Jan 1, 2024

Initial thought is that you are comparing this wrong. Youtube plays high def audio at sampling rate of 44K, 48k, 96k and so on. This just means that the audio has more rich info encoded, thus being able to emit more specific frequency sound. When you generate this via the library code then ZenTone generates audio at a default sampling rate of 44k.

However you can pass a different sampling rate into the constructor, when initializing ZenTone

val zentone = ZoneTone(sampleRate = 96000, encoding = AudioFormat.ENCODING_PCM_32BIT, channelMask = AudioFormat.CHANNEL_OUT_STEREO)

Similarly changing the encoding also has an effect.

The parameters that one uses effects how your audio sounds. Under the hood ZenTone doesn't do any magic, but generate byte data that is played over your audio output i.e speakers

If this does not fix your problem, then I will try to investigate this further and pin down how to achieve the similar sounding audio.

@vycoder
Copy link
Author

vycoder commented Jan 1, 2024

Thanks for the response.

I've tried increasing the sampleRate to 96000 exactly the example you provided. But it still seems a bit different, A frequency of 200 in Zentone, sounds a bit high-pitched, at least from what I hear. I've tried playing the same frequency in Tonejs, but they all sound like the one on YouTube, I don't think it has something to do with audio quality.

Tonejs, YouTube, and others all sound similar, 200Hz is a bit lower-pitched, similar to this: https://www.rapidtables.com/tools/tone-generator.html?f=200

I've tested ZenTone in the emulator and in the actual device but 200 Hz still sounds high-pitched compared to others. I'm not sure if I'm missing something, I know ZenTone doesn't do any magic, and it just plays a sine wave byte data which is why it confuses me how it doesn't sound similar.

Would appreciate any help in shedding light on where could be the issue.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants