electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
wave playback trouble
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [18 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
salamanderanagram



Joined: Apr 08, 2007
Posts: 20
Location: VT

PostPosted: Mon Nov 17, 2008 11:21 am    Post subject: wave playback trouble
Subject description: dropping entire instruments?
Reply with quote  Mark this post and the followings unread

hey y'all, i'm curious how this could possibly happen, it's quite strange.

my code looks like this. there's other stuff going on of course but this is really everything important.

SndBuf snd => dac;
"filename.wav" => snd.read;

while (true) {
1::second=>now;
}

now when i play some wave files it plays them back flawlessly. however, i tried playing back some .wav files that i made and it drops entire instruments out of the playback!! for example one song i wrote starts off with some violin and a drumbeat (and plays back as such in ITunes and Winamp) yet when i play it using this method, the violin cuts out entirely! i tried resaving and renaming the file, converting it to 48 KHz instead of 44.1, etc. etc. etc.

How can that even happen?

Last edited by salamanderanagram on Mon Nov 17, 2008 6:54 pm; edited 1 time in total
Back to top
View user's profile Send private message
telstarmagikistferrari



Joined: Jun 16, 2008
Posts: 280
Location: Indianapolis, Indiana
Audio files: 43

PostPosted: Mon Nov 17, 2008 5:44 pm    Post subject: Reply with quote  Mark this post and the followings unread

wow. in any case it sounds like a whole hell of a lot of weed was involved.
Shocked
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
salamanderanagram



Joined: Apr 08, 2007
Posts: 20
Location: VT

PostPosted: Mon Nov 17, 2008 6:52 pm    Post subject: Reply with quote  Mark this post and the followings unread

well you are certainly correct about that good sir, but really...

if there is a way to strip individual instruments out of .wav files i'd like to know how!! i simply don't understand it.

EDIT i just copy-pasted the code above into a new file that does nothing but attempt to play a .wav and it still happens...
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Mon Nov 17, 2008 8:16 pm    Post subject: Reply with quote  Mark this post and the followings unread

Ok. My bet is that this is a stereo file and these instruments are exactly 180° out of phase between the left and right channels, then canceling.

Could you try what happens if you use a mono version? If that turns out to be it we can then move on to making stereo work for you but I'd like to try this first.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
salamanderanagram



Joined: Apr 08, 2007
Posts: 20
Location: VT

PostPosted: Mon Nov 17, 2008 9:13 pm    Post subject: Reply with quote  Mark this post and the followings unread

huh.
i had a similar thought and try panning it all left or right and got no results.

but mono works fine... what am i doing wrong? i'm quite a noob at chuck and was just fooling around...
Back to top
View user's profile Send private message
salamanderanagram



Joined: Apr 08, 2007
Posts: 20
Location: VT

PostPosted: Fri Nov 21, 2008 10:06 am    Post subject: Reply with quote  Mark this post and the followings unread

so does anybody know how to play a stereo file in chuck or am i stuck in mono?
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Nov 21, 2008 2:31 pm    Post subject: Reply with quote  Mark this post and the followings unread

I'm fairly sure this should work but I don't quickly have a stereo test file on this computer. Anyway, try this and see how far it gets you;
Code:

SndBuf buf;

"myStereoFile.wav" => buf.read;

buf.chan(0) => dac.left;
buf.chan(1) => dac.right;

hour => now;

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Nov 21, 2008 2:46 pm    Post subject: Reply with quote  Mark this post and the followings unread

After giving it some more thought I now feel you were right to expect a automatic stereo connection. After all; Pan2 has a stereo output and that UGen automatically connects to the dac in stereo if chucked to it.

[edit]
After yet more thought I take that back :¬)
Unlike Pan2 SndBuf has no pre-determined number of channels; it may load a multi-channel wave files *after* it has been connected to the dac, so that would lead to issues.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
salamanderanagram



Joined: Apr 08, 2007
Posts: 20
Location: VT

PostPosted: Fri Nov 21, 2008 4:09 pm    Post subject: Reply with quote  Mark this post and the followings unread

thanks
but no dice. i get a null pointer from that code, maybe some minor error or oversight? i did try several other, similar methods to no avail tho.

EDIT

buf.chan(1) => dac.right;

causes the null pointer which is odd because if you read the number of channels in buf it gives back 2.
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Nov 21, 2008 7:12 pm    Post subject: Reply with quote  Mark this post and the followings unread

salamanderanagram wrote:

causes the null pointer which is odd because if you read the number of channels in buf it gives back 2.


That's weird! I had the same but I had no file loaded. Did you make sure to load a file *before* connecting to the dac? If so this is a bug and should be reported.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
salamanderanagram



Joined: Apr 08, 2007
Posts: 20
Location: VT

PostPosted: Fri Nov 21, 2008 7:27 pm    Post subject: Reply with quote  Mark this post and the followings unread

yeah i used exactly your code except changed the file name of course.

also i put in

buf.channels() =>int ch;
<<<ch>>>;

and it would say 2 channels on every test but when trying to access buf.chan(1) gives an error... weird.
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Nov 21, 2008 8:11 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hmmmm, likely a bug but I just noticed that the docs on SndBuf don't actually mention .chan(). I suppose it could be that SndBuf is only meant to play a single channel but that you can pick which one you'd like to play from multi-channel files (creating the need to use two buf's for stereo). That sounds quite inconvenient though.

I suggest you report the issue to the mailing-list to make sure it's a bug but at the very least *something* is wrong here.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
salamanderanagram



Joined: Apr 08, 2007
Posts: 20
Location: VT

PostPosted: Sun Nov 23, 2008 6:05 pm    Post subject: got it! Reply with quote  Mark this post and the followings unread

after a whole bunch of experimentation and a little bit of consulting the manual, here's how to play a stereo wave file in chuck -

SndBuf sndl;
"sound.wav" => sndl.read;
sndl.channel(0);
sndl=>dac.left;

SndBuf sndr;
"sound.wav" => sndr.read;
sndr.channel(1);
sndr=>dac.right;

hour => now;

probably i'll design a class for this tonight to be contained as one piece! thanks for your help kassen
Back to top
View user's profile Send private message
telstarmagikistferrari



Joined: Jun 16, 2008
Posts: 280
Location: Indianapolis, Indiana
Audio files: 43

PostPosted: Mon Nov 24, 2008 5:33 pm    Post subject: Reply with quote  Mark this post and the followings unread

this is great. well done. economical code! this will be endlessly useful.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Mon Nov 24, 2008 7:42 pm    Post subject: Reply with quote  Mark this post and the followings unread

A small suggestion;
Code:

SndBuf snd[2];

for(int n; n<snd.cap(); n++)
   {
   "sound.wav" => snd[n].read;
   snd[n].channel(n);
        //this is equivalent to left&right
   snd[n]=>dac.chan(n);
   }


hour => now;


This is a bit smaller but more importantly it'll make controlling the whole thing easier and as you're never typing the same thing twice it's less error-prone.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
salamanderanagram



Joined: Apr 08, 2007
Posts: 20
Location: VT

PostPosted: Tue Nov 25, 2008 11:19 am    Post subject: Reply with quote  Mark this post and the followings unread

hmmm.... strange i did try something like that and i kept getting this error, like "sndbuf[] has no element 'read()'" but now it's working fine with your code.. wonder what i did wrong. anyway, thanks!
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Tue Nov 25, 2008 11:41 am    Post subject: Reply with quote  Mark this post and the followings unread

salamanderanagram wrote:
"sndbuf[] has no element 'read()'"


That's right, it doesn't. A array of type SndBuf doesn't have a .read() member function but any one element in that array will have one. Similarly; you can add one to a element of a a array of integers but you can't add to the array itself as the array doesn't have a value, you *can* of course add a element to it but that's a different thing).

So in this case;

snd[1].read()

Here the blue part refers to a array of SndBufs, the red points to a specific element (which is a SndBuf) in it and the green refers to that element's member function.

It's important to realise that array locations are just like any other example of a object of that class, they can do the same things but like with anything else you are required to indicate what exact object you'd like to work with. We select from the general to the precise and once we arrive "at the bottom" we can actually interact with it.

I hope this clarifies. This is useful nearly everywhere where we have a group of object that we'd like to treat in a similar way. It nearly always leads to less code, less errors and generally more convenience.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
salamanderanagram



Joined: Apr 08, 2007
Posts: 20
Location: VT

PostPosted: Wed Nov 26, 2008 12:04 pm    Post subject: Reply with quote  Mark this post and the followings unread

nah i've been programming for 12 years, i understand usually all of this stuff... i must have been doing some esoteric error or stupid syntax mistake of some kind... thanks for the help!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [18 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use