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

wave module sets data subchunk size incorrectly when writing wav file #52558

Closed
JeffPursell mannequin opened this issue Apr 4, 2010 · 9 comments
Closed

wave module sets data subchunk size incorrectly when writing wav file #52558

JeffPursell mannequin opened this issue Apr 4, 2010 · 9 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@JeffPursell
Copy link
Mannequin

JeffPursell mannequin commented Apr 4, 2010

BPO 8311
Nosy @bitdancer, @serhiy-storchaka
Files
  • testTone.zip: zip file containing 2 .py files to demonstrate bug
  • wave_test_write_array.patch
  • audio_write_nonbytes.patch
  • audio_write_nonbytes_2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2013-11-16.12:06:03.295>
    created_at = <Date 2010-04-04.13:36:51.889>
    labels = ['type-feature', 'library']
    title = 'wave module sets data subchunk size incorrectly when writing wav file'
    updated_at = <Date 2014-03-08.17:54:17.144>
    user = 'https://bugs.python.org/JeffPursell'

    bugs.python.org fields:

    activity = <Date 2014-03-08.17:54:17.144>
    actor = 'python-dev'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2013-11-16.12:06:03.295>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2010-04-04.13:36:51.889>
    creator = 'Jeff.Pursell'
    dependencies = []
    files = ['16757', '31586', '32114', '32567']
    hgrepos = []
    issue_num = 8311
    keywords = ['patch']
    message_count = 9.0
    messages = ['102342', '102346', '102349', '196915', '199871', '202561', '203032', '203033', '212939']
    nosy_count = 4.0
    nosy_names = ['r.david.murray', 'Jeff.Pursell', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue8311'
    versions = ['Python 3.4']

    @JeffPursell
    Copy link
    Mannequin Author

    JeffPursell mannequin commented Apr 4, 2010

    I tried to create a 4 second file and only heard the first 2 seconds. The file size was correct for a 44.1 kHz, 16 bit mono file at 4 seconds, but both aplay and audactiy ignored the second half of the file. I went to this page https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ and opened the output with a hex editor in little endian mode. I found that at offset 40, the data chunk size was wrong. It looked like it was just set to the number of samples. It should be the number of samples times bytes-per-sample (2) times number-of-channels (1 in my case). I manually set the number from 176400 to 352800 and that solved the problem for that wav file.

    I'm guessing this was just an oversight and the fix will be simple.

    I'll attach the code I used to generate the test tone. Just run python -i testTone.py and it will generate out.wav with the incorrect field.

    I am using pything 2.6.4 in ubuntu.

    @JeffPursell JeffPursell mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Apr 4, 2010
    @JeffPursell
    Copy link
    Mannequin Author

    JeffPursell mannequin commented Apr 4, 2010

    Here's my fix. The left file is the original and the right file is my version. Perhaps someone should check this patch on a big endian machine to make sure there are no issues there. I do not anticipate any issues.

    416c416
    < nframes = len(data) // (self._sampwidth * self._nchannels)
    ---

        nframes = len(data) // self.\_nchannels
    

    427c427
    < self._datawritten = self._datawritten + len(data)
    ---

            self.\_datawritten = self.\_datawritten + len(data) * self.\_sampwidth
    

    463c463
    < self._nframes = initlength / (self._nchannels * self._sampwidth)
    ---

            self.\_nframes = initlength // self.\_nchannels
    

    @bitdancer
    Copy link
    Member

    Any chance you could create a unit test for this? (The current set of tests is...pretty minimal.) Also, having the patch in unified diff format relative to the top of the source three would be helpful (although this one is small enough we could certainly apply it by hand, having a unified diff makes it more likely someone will test it).

    @bitdancer bitdancer added stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels Apr 4, 2010
    @serhiy-storchaka
    Copy link
    Member

    It's because you write an array of integers while writeframes() expects a bytes object.

    Here is a test.

    @serhiy-storchaka
    Copy link
    Member

    Here is a patch for all three audio modules. After dropping support of string (which is meanless) in the audioop module (bpo-16685) it can be simplified.

    I doubt that this should be applied in maintenance releases. Support of non-bytes arguments in writerawframes() is a new feature.

    @serhiy-storchaka serhiy-storchaka self-assigned this Oct 14, 2013
    @serhiy-storchaka serhiy-storchaka added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Oct 14, 2013
    @serhiy-storchaka
    Copy link
    Member

    Here is simplified patch. Added versionchanged tags in the documentation.

    @serhiy-storchaka
    Copy link
    Member

    Committed in changeset b96f4ee1b08b.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 16, 2013

    New changeset 932db179585d by Serhiy Storchaka in branch 'default':
    Fixed issue number for issue bpo-8311.
    http://hg.python.org/cpython/rev/932db179585d

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Mar 8, 2014

    New changeset b72615222c98 by R David Murray in branch 'default':
    whatsnew: sunau/aifc/wave writeframes[raw] accept any bytes-like (bpo-8311)
    http://hg.python.org/cpython/rev/b72615222c98

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants