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

How to Access WAVEFORMATEX? #1

Open
cjunekim opened this issue Jan 7, 2019 · 3 comments
Open

How to Access WAVEFORMATEX? #1

cjunekim opened this issue Jan 7, 2019 · 3 comments

Comments

@cjunekim
Copy link

cjunekim commented Jan 7, 2019

Hello

I want to read the sample rate and bit depth for the current audio endpoint. It seems like the structure is called WAVEFORMATEX and it is in the library, but not utilized. How do I get this?

@cjunekim
Copy link
Author

cjunekim commented Jan 7, 2019

I could get the sample rate via,

>>> audiodevice.render_endpoints[0].audio_client.GetMixFormat().contents.nSamplesPerSec
48000

However, the bit depth is strange:

>>> audiodevice.render_endpoints[0].audio_client.GetMixFormat().contents.wBitsPerSample
5

The bit depth should be multiples of 8. The device's bit depth was set as 24 bit. However, wBitsPerSample value was 5.

@kdschlosser
Copy link
Owner

you may want to cast the pointer that is returned by GetMixFormat

so here would be an example.

import ctypes
from pyWinCoreAudio.__core_audio.audioclient import WAVEFORMATEEX

waveformatex = ctypes.cast(audiodevice.render_endpoints[0].audio_client.GetMixFormat(), ctypes.POINTER(WAVEFORMATEEX))

# I do not remember off hand which way you are going to be able to access the information
waveformatex.contents.wBitsPerSample

# or this
waveformatex.wBitsPerSample

You can give that a try.

Now I have not messed with this library in some time. but if memory serves the returned waveformatex structure is going to be the audio stream data. I would have to double check that.

The easiest way to be 100% sure is if you use Media Player to play an MP3 that you know the bitrate for (this can be found out by checking in the Windows Explorer (File Explorer) and look at the metadata for the MP3. and check to see if the returned value from GeetMixFormat is the same.

I would have to check and see if Microsoft used some kind of funky math for the bitarte they may have.

@kdschlosser
Copy link
Owner

kdschlosser commented Jan 8, 2019

ok never mind. I just realized you are trying to get the bit depth not the bit rate.
what kind of an audio format are you playing???

if is is not a lossless audio format you will get an incorrect value. during the encoding process alot of the time the bit depth data gets removed. see the link below.

https://stackoverflow.com/questions/27652123/how-to-know-the-bit-depth-of-a-mp3-file

also on Microsoft's API white papers it states

The GetMixFormat method retrieves the stream format that the audio engine uses for its internal processing of shared-mode streams.

the keyword in that is stream. not device.
https://docs.microsoft.com/en-us/windows/desktop/api/audioclient/nf-audioclient-iaudioclient-getmixformat

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