473,545 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.err or: 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.rj ust( 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 1445

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

Similar topics

3
2476
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 audio data look like? Is each word of the raw audio data a frequency? If I encode 440 for each of the frames, will I get concert A? Thanks for...
3
11029
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 an integer - now I know that in C I'd just cast a pointer to the offset to a short, and that python doesn't cast, so how can I extract the value from...
10
3070
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 that Numerology program I wrote years ago in VB. There are times I am totally stuck (for instance, I just had an idea to put the numerical values of...
3
2293
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 and classes. In most cases these dependencies end-up in external systems such as databases and OS. Overhead in designing systems with "could be...
5
3099
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 name from Windows XP and 2000; >>>print win32api.FindFiles(process_source_dir + "*") Excluding the results from "." and "..", it returns: (32,...
0
3916
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header,...
2
2812
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 firewall software may warn about the connection IDLE makes to its subprocess using this computer's internal loopback interface. This connection is...
3
1309
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. Now, the problem is that I happen to write two of these with the same name in different modules that don't know anything
4
3518
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 that user time is 39.85 sec, but 'time' command reports that user time is 28.55sec. (machine: Python2.5, MacOS X 10.4 Tiger, MacBook 1.83GHz intel...
0
7416
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7676
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7932
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6001
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5347
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1905
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
729
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.