Coder Social home page Coder Social logo

Comments (7)

spacether avatar spacether commented on June 13, 2024

@yoyoberenguer can you try using the 2.0.0 version of pianoputer and verify that this issue is fixed?
When I load in mono and stereo wavs into v2.0.0 I do not get the error in this issue so I think that this is fixed.
If I don't hear from you in the next week or two I will close this issue because I can't replicate it.

from pianoputer.

yoyoberenguer avatar yoyoberenguer commented on June 13, 2024

@spacether,
Good day to you.
First nice job on the last version 2.0.0 of pianoputer, it looks so much better.

I can confirm the issue persist with pygame version 2.0 (I am attaching the screenshots proving it and also the resolution that will make your life easier)
Here is the exception raised when loading (python 3.8 and pygame 2.0)
CapturePython38

Here is the resolution (python 3.8 and pygame 2.0)
CapturePython38_NoError

Resolution :
pygame.mixer.init(framerate_hz, BITS_32BIT, channels, allowedchanges=0)

Bear in mind that allowedchanges has been implemented recently in pygame and some older version will not recognized
this statement. In order to have a retro compatibility with odler version, you will have to implement some sort
of pygame.version detection and change accordingly (pianoputer won't throw an exception when using older version of
pygame < 2.0)

Also I didn't have time to look into the code but I noticed a bug in the method get_audio_data

    try:
        channels = len(audio_data[0])
    except TypeError:
        channels = 1
    return audio_data, framerate_hz, channels

For a single track, the numpy.ndarray will by shape e.g (31728, ) and for a stereo (31728, 2)
The channel number is always referenced by the index 1 of the array (only for stereo or above) such as :
channels = audio_data[1]
index 0 is the samples data length
Your code above will always revert to a mono track and will never detect a stereo sound
(and this explained why you could not replicate the issue).


def is_valid_array(array_)->bool:
    
    # DETERMINE IF THE ARRAY IS MONO OR STEREO AND RETURN TRUE IF VALID 
    
    # check the shape of an array
    if hasatttr(array_, 'shape'):
        if len(array_.shape) == 1: return True  # mono sound
        elif len(array_.shape) == 2:
            if array_.shape[1] <=2: return True # stereo sound
            else: return False
        else: return False  # more than 2 channel not implemented yet
    else: return False  # here Attribute Error, certainly not an ndarray type

from pianoputer.

spacether avatar spacether commented on June 13, 2024

Thank you for the explanation. What OS are you using?
Is this happening for stereo and mono files?
On MacOS I am unable to reproduce the issue.
On Windows10Pro I can reproduce the issue for mono files.

  • the channel is being correctly detected as 1, mono wavs are produced, and something is going wrong with make_sound or the mixer. I am investigating it.

Good point about channels > 2, I should handle that use case.

from pianoputer.

spacether avatar spacether commented on June 13, 2024

Very weird, we are initializing the mixer with 1 channel for the mono wav file but on:

  • windoes10pro pygame.mixer.get_init() returns (4800, -32, 2)
  • and on macOs it reports (4800, -32, 1)

from pianoputer.

spacether avatar spacether commented on June 13, 2024

I have filed a pygame bug on this at pygame/pygame#2417
Edit: and I just closed the bug because passing in your suggested allowedchanges=0 solves it

from pianoputer.

spacether avatar spacether commented on June 13, 2024

A fix has been submitted for this issue at #22

from pianoputer.

spacether avatar spacether commented on June 13, 2024

@yoyoberenguer thank you for submitting this problem and letting us know how to fix it!
With v2.0.1 this issue should be resolved
On WIndows10Pro I ran the tests and verified that generating 1, 2, and 4 channel wav files works and that we no longer get this exception. If this problem is still occurring can you re-open this issue?

from pianoputer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.