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

PCM playback sped up #60

Closed
Frodriguez26 opened this issue May 16, 2018 · 7 comments
Closed

PCM playback sped up #60

Frodriguez26 opened this issue May 16, 2018 · 7 comments

Comments

@Frodriguez26
Copy link

`
This is a great project! Though I have an issue with the play back speed. I have been searching for an answer for a couple weeks now and I haven't found anything yet.

I am using a slightly modified version of the recordtest.py example from the main github page:

import alsaaudio
import time

f = open("out_test.raw", "wb")
inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, cardindex=1

# Set attributes: Mono, 44100 Hz, 16 bit little endian samples
inp.setchannels(1)
inp.setrate(44100)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
inp.setperiodsize(160)

loops = 1000000
while loops > 0:
    loops -= 1
    # Read data from device
    l, data = inp.read()

    if l:
        f.write(data)
        time.sleep(.001)

and I am also using a modified version of the playbacktest.py examples which looks like:

import time
import alsaaudio

index = 1
f = open('out_test.raw', 'rb')
# Open the device in playback mode.
out = alsaaudio.PCM(alsaaudio.PCM_PLAYBACK, cardindex = index)

# Set attributes: Mono, 44100 Hz, 16 bit little endian frames
out.setchannels(1)
out.setrate(44100)
out.setformat(alsaaudio.PCM_FORMAT_S16_LE)

# The period size controls the internal number of frames per period.
# The significance of this parameter is documented in the ALSA api.
out.setperiodsize(160)

# Read data from stdin
data = f.read(320)
while data:
    out.write(data)
    data = f.read(320)

When I run the recordtest.py, it seems to work fine and I am able to hear the recording with:

aplay -D plughw:1 -f S16_LE -r 44100 out_test.raw

But when I try using playbacktest.py file, it plays the sound very fast. I have tried changing the rate, periodsize and buffer size and none of those change the speed at which the file is being played. I have also tried saving the recording into a wave file then playing it using the playwav.py example and it is still sped up.

I am using a raspberry pi 3 with a usb sound card hooked up to the usb port. Thanks for the help!
`

@riverar
Copy link

riverar commented Aug 28, 2018

Can confirm this on 0.8.4 as well with similar hardware.

@aidanhb
Copy link

aidanhb commented Oct 25, 2018

Third-ed on 0.8.4 for a PreSonus Audiobox soundcard. Sounds fine on system speakers.

@ozett
Copy link

ozett commented Dec 4, 2018

i have raspberry pi zero W,
sounds play ok with aplay, very fast with default test...
i confirm search fo an answer here..

@ShellAddicted
Copy link

I'll just leave this here, may work or not, (it did on my machine)
Specify the device as plughw example: plughw:1,0

@akamensky
Copy link

akamensky commented Jan 7, 2021

Same on RPi 4B w/ Ubuntu 20.10 64bit.

@ShellAddicted using plughw sink makes no difference on my end.

Ping @larsimmisch perhaps? Seems this issue has been around since 2018 is still present.

Library installed from pip install

@ossilator
Copy link
Collaborator

is this reproducible with v0.9, using the new method to parameterize the pcm object?

@ossilator
Copy link
Collaborator

hmm, the plughw hint should have worked if applied correctly, because the most likely reason for the failure is that alsa chose different stream parameters than requested, due to hardware limitations. that shouldn't happen with plughw. this hypothesis can be verified by calling out.dumpinfo().

alternatively, this might have been fixed along with #63, hence my question above.

so i'm closing this as "need more info".

@ossilator ossilator closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2024
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

7 participants