473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need help with struct and aifc modules.

sj
Im trying to read sample values from aiff files but can not seem to get the
unpacking right. Ths following code reads n frames from a sample file and
prints the amplitudes to the terminal. In the call to struct.unpack 'h' is
the only formating string I can use without getting the message
"struct.error: unpack str size does not match format"

However the output is wrong. The test file contains a single cycle sine
wave which is positive for the first 50 samples. What am I doing wrong?

import aifc
import struct
import string

def dump_frames( file, start=0, end=None):
fobj = aifc.open( file, 'r')
fobj.setpos( start)
if not end:
end = fobj.getnframes()
index = start
while index < end:
raw = fobj.readframes(1)
val = struct.unpack("h", raw)[0]
print "Frame ", string.rjust( str(index), 8), " : ",
print "Value ",string.rjust( str(val), 12)
index += 1


sfile = "/samples/test.aiff"
print get_aiff_stats( sfile)
aifc file /samples/test.aiff
n channels 1
sample width 2
frame rate 44100
n frames 100
compression NONE not compressed
markers: NONE
dump_frames( sfile, 0, 11)

Frame 0 : Value 0
Frame 1 : Value 14343
Frame 2 : Value 26638
Frame 3 : Value -30187
Frame 4 : Value -27108
Frame 5 : Value -31453
Frame 6 : Value 20778
Frame 7 : Value -3536
Frame 8 : Value 25143
Frame 9 : Value -26051
Frame 10 : Value -27581

--
Replace underscores in email address to reply
Jul 18 '05 #1
0 1436

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kelvin Chu | last post by:
Hello, Python Wizards... I'm trying to use Python to write an aiff file. I've used the aifc module and I've set the parameters (# of channels, encoding rate, compression, etc.) What does raw...
3
by: Graham Nicholls | last post by:
Hi, I'm trying to size a jpeg file. The file size is held in a short (2 byte integer) at a certain offset. Once I've found these two bytes (they're in MSB,LSB order), I need to convert them to...
10
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting...
3
by: Andrew | last post by:
Hi, I am thinking about ways for efficient techniques for isolation testing. Here is the problem as I see it: Complex OO systems are designed with massive number of dependencies between modules...
5
by: Frank Borell | last post by:
I'm having a problem retrieving the ShortName from a file that was written by a MAC and only from a Windows 2003 server. I realize the file has a space after it, but I can retrieve the short...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
2
by: gen_tricomi | last post by:
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32 Type "copyright", "credits" or "license()" for more information. **************************************************************** Personal...
3
by: catphive.lists | last post by:
I have a bunch of function object classes of the form struct MyFunc : unary_function<arg,ret> { MyFunc(arg) : state(arg) {} void operator() (arg) { /*code here*/ } }; in various cpp files....
4
by: kwatch | last post by:
Hi, I have a question about os.times(). os.times() returns a tuple containing user time and system time, but it is not matched to the result of 'time' command. For example, os.times() reports...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.