f



MATLAB's SOUND() function in C

Is there a way to implement MATLAB's sound function under C?

For those who don't use MATLAB, it's essentially a simplistic, static,
mono sound function that converts a series a numbers into a sound at a
given sampling rate.  nothing fancy.  all the Sound APIs begin by
discussing all the fancy drivers and buffers and crazy shit i don't
really care about.

Thanks.

0
sluox
7/1/2006 6:36:57 PM
comp.sys.mac.programmer.misc 790 articles. 0 followers. Post Follow

3 Replies
1223 Views

Similar Articles

[PageSpeed] 44

In article <1151779016.882805.282580@d56g2000cwd.googlegroups.com>,
 sluox@yahoo.com wrote:

> Is there a way to implement MATLAB's sound function under C?
> 
> For those who don't use MATLAB, it's essentially a simplistic, static,
> mono sound function that converts a series a numbers into a sound at a
> given sampling rate.  nothing fancy.  all the Sound APIs begin by
> discussing all the fancy drivers and buffers and crazy shit i don't
> really care about.
> 
> Thanks.

The basic thing to do is:

  - SndNewChannel
  - SndDoCommand to send a bufferCommand
  - SndDisposeChannel

If you intend to play the sound asynchronously, be careful to not 
dispose the sound channel or the buffer you play before the sound has 
finished playing (install a callback using SndDoCommand, if you want to 
be informed when that is)

For more info, take a look at the function 
SndSnip_PlaySoundResourceUsingBufferCmds in SoundSnippets.c 
(<http://developer.apple.com/samplecode/soundsnippets/listing1.html>).

Reinder
0
Reinder
7/1/2006 7:19:41 PM
Reinder Verlinde:
> 
> The basic thing to do is:
> 
>   - SndNewChannel
>   - SndDoCommand to send a bufferCommand
>   - SndDisposeChannel

The downside to this is that it uses the Sound Manager, which is
deprecated and doesn't support all standard hardware configurations
(specifically, recent Macs built-in sound chip set at high sampling
rates), let alone third-party systems.

Core Audio is very much recommended. Unfortunately, the examples at
/Developer/Examples/CoreAudio/SimpleSDK/ are about as easy as it gets.


-- 
Jens Ayton
0
Jens
7/1/2006 7:37:14 PM
In article <K9Apg.7099$E02.2135@newsb.telia.net>,
 Jens Ayton <QUSIWRYXFXBF@spammotel.com> wrote:

> Reinder Verlinde:
> > 
> > The basic thing to do is:
> > 
> >   - SndNewChannel
> >   - SndDoCommand to send a bufferCommand
> >   - SndDisposeChannel
> 
> The downside to this is that it uses the Sound Manager, which is
> deprecated and doesn't support all standard hardware configurations
> (specifically, recent Macs built-in sound chip set at high sampling
> rates), let alone third-party systems.

Oops. I knew the online documentation is a mess, so I should have 
searched better. To my defense, I did check out 
<http://developer.apple.com/technotes/tn/tn1198.html>, which seems to 
point out that major parts of the Sound Manager are still supported. In 
my first search, I could not find any newer info.

A new search, Googling for "sound manager deprecated site:apple.com" 
lead me to <http://developer.apple.com/qa/qa2005/qa1448.html>, which 
confirms your statement.

So, yes, you should probably not use the Sound Manager in new code. 
There does not seem to be a new API at the same abstraction level.

> Core Audio is very much recommended. Unfortunately, the examples at
> /Developer/Examples/CoreAudio/SimpleSDK/ are about as easy as it gets.

If you want to tackle Core Audio, 
<http://www.audiosynth.com/sinewavedemo.html> might be a starting point.

If you can require Tiger, OpenAL might be a better option than 
programming CoreAudio directly. I have never programmed it, but it 
appears to hide some of the complexity of Core Audio. On the other hand, 
it adds the complexity that allows you to move sound sources around in 
3D.

Reinder
0
Reinder
7/1/2006 9:30:41 PM
Reply:

Similar Artilces:

Error while obtaining sizes from MEX S-function 'forward' in block 'dummy/Dynamic_Model/S-Function'. MATLAB error message:.
Hi to everybody, I created the file forward.dll using the command: mex -DWIN32 -output forward model_d.c model_s.c sdlib.c assigns.c contact.c derivs.c gmc.c impact.c inits.c invert.c lcp_solver.c lmdif_c.c mathtools.c object.c output.c pipetools.c readmuscles.c readtools.c sdfor.c spring_based.c wrapping.c gcvspl.c user_def.lib forward.lib acpp.lib qhull.lib solid.lib wrap.lib I need to run the command: set_param([subsystemname,'/','S-Function'],'function name','forward','parameters','[0],[0],[0],[0],[0],[0],[1 0 0 0 20],[0]'); ...

Is it possible to create 'beep' sound from within c-mex s-function?
I have a c-mex s-function that I would like to generate a beep (or similar warning/alert sound) as a user interacts with it. The regular Matlab 'beep' command causes an error when compiled. From my searches, I see that this has been asked by others previously, but I haven't encountered any answers to this question. I don't see this issue mentioned in the Matlab documentation. I believe it also may be possible to play a .wav or other audio file on command, if a simple beep function/sound isn't available; however, my searches of the documentation haven't revealed how to do this, either. Thanks in advance for your help! If you're on Windows then you can create your own beep. Just include <windows.h> and then use the function Beep(Frequency, duration) Something like Beep(750,100) is similar to the standard beep. Phil. Thanks for your help, Phil. The windows Beep() function works nicely! ...

Matlab's 'graycomatrix' function
I have one question: Is Matlab's 'graycomatrix' function actually in accordance with original Haralick's 1973 paper? I mean, are they supposed to be the same algorithm? If yes, I don't think Matlab did a good job on this. For example, try it on this matrix (i.e., 'image'): 0 0 1 1 0 0 1 1 0 2 2 2 2 2 3 3 This matrix is in Haralick's original paper and the results can be compared. Can anybody ellaborate if you used it? Thank you. "Bulent Bayraktar" <bayrakta@purdue.edu> writes: > I have one question: Is Matlab's 'graycomatrix' function actually in > accordance with original Haralick's 1973 paper? > I mean, are they supposed to be the same algorithm? If yes, I don't > think Matlab did a good job on this. > > For example, try it on this matrix (i.e., 'image'): > 0 0 1 1 > 0 0 1 1 > 0 2 2 2 > 2 2 3 3 > > This matrix is in Haralick's original paper and the results can be > compared. > > Can anybody ellaborate if you used it? You do need to understand a bit about the conventions used in the software you are using. For example, the Image Processing Toolbox's default black-to-white range for double-precision inputs is [0, 1]. The reference page for graycomatrix describes in detail what it does. By default, for example, it quantizes the range [0, 1] into 8 levels, resulting in an 8-by-8 co-occurrence matrix. But for your matrix, it is seeing 5 &qu...

MatLab's 'movie' function
Hi! Using MatLab's 'movie' function you can play a movie recorded by the 'getframe' command. It is possible to specify the number of times the movie is played and the frames per second. Unfortunately, I've not found a way to stop the playback of a movie. Is it possible to, let's say I've specified the movie should be played 20 times, to disrupt the playback after an user interrupt?! Thanks a lot, Chris On Sat, 12 Feb 2005 10:40:06 +0100, Christoph ROLZ wrote: >Hi! > >Using MatLab's 'movie' function you can play a movie recorded by the >'getframe' command. It is possible to specify the number of times the >movie is played and the frames per second. > >Unfortunately, I've not found a way to stop the playback of a movie. > >Is it possible to, let's say I've specified the movie should be played >20 times, to disrupt the playback after an user interrupt?! > >Thanks a lot, > Chris if you want to play the movie, tried thi command index is the number of frame in video file. index = 1:100 mov = aviread('filename',index) for i = 1: 100 frame = mov(i).cdata; imshow(frame) end Please try it. ...

Writing C MEX S-Function from existing Matlab C MEX function
I have an existing Matlab C MEX function (walkode.dll) that returns state derivatives when called by ode23s (walkode,...) from a regular Matlab script or the command line. I would like to incorporate this into a Simulink model, and have done so using a Level 1 M-file S-function, which called walkode in the mdlDerivatives subfunction. However this model runs very slowly. I would prefer to rewrite (recompile?) my .dll as a C MEX S- function (using sfuntmpl_doc.c I believe), but I am unsure as how to go about doing so. This is where my understanding (or more aptly, misunderstanding) of C,...

matlab like c's getchar function
In c-language, the getchar function can get standinput. In MATLAB, the function call which name? akira32 wrote: > > > In c-language, the getchar function can get standinput. > In MATLAB, the function call which name? Look for getcharkey on the matlab file exchange. <http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=7465> It may do what you want. Jos Jos wrote: <SNIP ... getcharkey ... AD comes early this year. I meant GETKEY Jos <x@y.z> wrote in message <ef5b00e.1@webcrossing.raydaftYaTP>... > Jos wrote: > <SNIP ... ...

Trial of Musatov's theory: double spaced 'e x p a n d s' and single spaced 'c o n t r a c t s'. Does the spacing post-processing appear equal? If so, what force was lost and where did it g
Musatov's theory 'The space between spaces expands and contracts.' Would this give time a direction? Musatov ...

Output returned by S-function 'xxxxxxx' in 'xxxxx/S-Function' during flag=3 call must be a real vector of length 1
Hi there, I've found several posts where people are experiencing this error "Output returned by S-function 'xxxxxxx' in 'xxxxxxx/S-Function' during flag=3 call must be a real vector of length 1" but I haven't been able to access a definitive solution. My m-files ran successfully with my previously installed version of Matlab/Simulink (i think V12 from 2000) but I've just upgraded to 2011a and now see this error. in InitializeSizes(u): sizes.NumOutputs = 1; sizes.NumInputs = 2; in Output(t,u): if u(2) == 0 u(2) = 1; end sys = u(1)/u(2); Does anyone have any hints? Is there a new syntax? cheers, Mel "Mel Cutler" <melcinasia@yahoo.co.nz> wrote in message news:iq7t6t$2ld$1@newscl01ah.mathworks.com... > Hi there, > > I've found several posts where people are experiencing this error > "Output returned by S-function 'xxxxxxx' in 'xxxxxxx/S-Function' during > flag=3 call must be a real vector of length 1" but I haven't been able to > access a definitive solution. > > My m-files ran successfully with my previously installed version of > Matlab/Simulink (i think V12 from 2000) but I've just upgraded to 2011a > and now see this error. > > in InitializeSizes(u): > sizes.NumOutputs = 1; > sizes.NumInputs = 2; > > in Output(t,u): > if u(2) == 0 > u(2) = 1; > end > sys = u(1)/u(2); > > Does anyone...

use of Matlab functions for 'c++'
Hi!!! I'm working with SystemC that is something like a c++ library, and I wanna know how can I use the Matlab functions for 'c++'. I think there is a principal function called 'mexFunction' which is the gateway routine to call all that functions but I've already a 'main' function so I don't know if I can use both or how can I use it without the main, because I need the main function. Thanks. Laura wrote: > Hi!!! I'm working with SystemC that is something like a c++ library, > and I wanna know how can I use the Matlab functions for 'c++'. ...

More factory sealed FPGA's with C of C's
I have more FPGA's with C of C's that I can supply below facotry direct pricing. Small quantities ok. These have all been purchased thru factrory direct channels and in most cases I can tell you exactly where they came from. We have aquired these from VMI and SMI programs that we have with major OEM's and CM's. Jon E. Hansen Pyramid Technologies Inc. jon@pyramidemail.com www.pyramidtechnologiesinc.com (949)864-7745 Direct (949)636-1416 Cell CERTIFIED ISO 9001:2000 XC5VFX70T-1FF1136C XC5VFX70T-1FFG1136C XC5VLX50-1FF676C XC5VLX330-1FF1760C XC4VLX100-10FFG1148C XC2V3000-4FG...

What's the C++ community's feeling about lambda(or closure) in C++?
I know this topic sounds kind of old and dry(and shallow, maybe :)), but, you see, lately I found that there's all the fuss about closure in Java, so I poked around for a little, and did find some valuable information. And I started to remember that there were a proposal(actually two) about lambda/closure for C++(see http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1968.pdf and http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1958.pdf) They're all pretty well-formed and sound, though I found Bjarne's a little more comprehensive. It simply seems that the closure id...

C version of C++'s virtual functions
How can C be used to created a "Vtable" like C++'s virtual functions? I bet this involves struct. Lost Bill -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! -----== Over 80,000 Newsgroups - 16 Different Servers! =----- In 'comp.lang.c', "Bill Cunningham" <some@some.net> wrote: > How can C be used to created a "Vtable" like C++'s virtual functions? I bet > this involves struct. You have to fiddle with pointers to functions. -- -ed- emdelY...

C programmers! How do you use your 'enum's ?
Dear mates, This is just a small survey for the common (and uncommon) nontrivial uses of the aforementioned C construct. It's posted by an average C programmer who's curious about how his elder colleagues utilize this feature of C in their implementations based on diverse programming styles in diverse application domains. Thank you for your interest. Best regards, //rk Razmig K <strontium90@postmaster.co.uk> wrote: > Dear mates, > > This is just a small survey for the common (and uncommon) nontrivial > uses of the aforementioned C construct. > It's posted ...

Question about 'fread' in C-S-Function
I made an xpc target model. There is a data (one demension vector with 500 elements) always need to be read and saved(overwritten). I'm using "xpc target scope"(type file) to save the data(test.dat) to harddisk of xpc. To read the data I once made an M-file like following: % Attach to the target PC file system. f=xpctarget.fs; % Open the file, read the data, close the file. h=fopen(f,'test.dat'); data=fread(f,h); fclose(f,h); % Unpack the data. x=readxpcfile(data); But it can only work on host pc. Now I need to make a C-S-Function to realise it on target pc and have 2 problems. 1 In C-Program here should be 'fread(buffer,size,count,fp)', can anyone help me how to set here 'buffer','size' and 'count'? 2 The C-S-Functio doesn't kown 'readxpcfile', then how can I unpack and get the end data x? ...

How to link obj's from c-source with obj's from c++-source
Hi, I compiled 2 simple source-files with cl -c main.cpp and cl -c test.c. test.c contains just a simple function, which is declared in test.h. test.h is included in test.c and in main.cpp. When I try to link the objects with link main.cpp test.c -out:prog.exe I get the error: "main.obj : error LNK2019: unresolved external Symbol "int __cdecl greater(int,int)" (?greater@@YAHHH@Z), called in function _main prog.exe : fatal error LNK1120: 1 unresolved external Symbol" What have I to do, to be able to link those objects together? Guido Belligoi "Guido Belligoi" ...

[News] ODF a Programmer's Friend, OOXML a Programmer's Foe
Web and Application development ,----[ Quote ] | How well is ODF and OOXML supported in different languages? | | I started off by choosing six common languages used by application and Web | developers, then I went and looked for what libraries are available for each | document format: | Language ODF OOXML | Python Yes No | Perl Yes No | Ruby Yes No | PHP Yes Started | Java Yes Started | Microsoft C# Yes Yes `---- http://commandline.org.uk/more/formats/library-shootout-odf-vs-ooxml-2007-11-28-00-03.html...

Q: C macro's for lvalue statements ? Any C marco Guru's out there ?
Hi everybody, I've got a problem implementing some macros that would make my code much more readable. The idea: I have a set of macros that create variable names depending of the content of some other define. An example (of how it should look like in the end): // --------------- cut #define BASE_NAME module1 // the macro(s) which I need help for :-) #define MAKE_VARNAME2(base, var,val) int var#_#base = val #define MAKE_VARNAME(var, val) MAKE_VARNAME2(BASE_NAME, var, val) // the usage example MAKE_VARNAME(status, 0); // --------------- cut which should expand to int status_module1...

How to call a component's callback function in another component's callback function
How to call a component's callback function in another component's callback function? I want to call popup menu's call back function in push button's call back function. What should I do and how? I will be grateful to you for you help! Thank you, Regards, Ahmed Just call it like you would any other function. The only thing you have to worry about is parsing arguments in the callback that is called from multiple sources. This example illustrates the difference: %---------------------------------------------------------------------------------------% function [] = call...

How to add the solver's option in Simulink's s-function
I have a system described in differential equations and I have include the options in the differential equation solving, and I incorporated it in the s-function block and put it in the Simulink. Here are my options and ode solver options = odeset ('Mass',@xu_mass,'MassSingular','yes','MStateDependence','strong'); % odeset('MaxStep','1e-3'); % odeset('RelTol',1e-3,'AbsTol',1e-3); domain = 0:1e-4:8; [t,y]=ode23(@xu_eq,domain,[0;zeros(7,1)],options); However, I don't know where to add the options to the simulation. Please help. Thanks in advance! On 2=D4=C27=C8=D5, =C9=CF=CE=E710=CA=B120=B7=D6, workaholic <liua...@gmail.= com> wrote: > I have a system described in differential equations and I have include > the options in the differential equation solving, and I incorporated > it in the s-function block and put it in the Simulink. > > Here are my options and ode solver > options =3D odeset > ('Mass',@xu_mass,'MassSingular','yes','MStateDependence','strong'); > % odeset('MaxStep','1e-3'); > > % odeset('RelTol',1e-3,'AbsTol',1e-3); > domain =3D 0:1e-4:8; > [t,y]=3Dode23(@xu_eq,domain,[0;zeros(7,1)],options); > > However, I don't know where to add the options to the simulation. > Please help. > > Thanks in advance! Is there anyone who met such a problem? Thanks again in...

Modify tunable global parameters in 'C' S-Function
I am creating a Simulink model with a large number of parameters. I would like for the values of these parameters to be reconfigurable after deployment (i.e., after code generation and binary executable distribution) via a human-readable configuration file. My reasons for wanting to change these values in the field are due to changes in sensors and external environments as well as debugging in actual hardware. I have created a 'C' S-Function which parses my configuration file and auto-magically determines the names, types and values of the tunable parameters. My issue is with reg...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

ndefined function or variable 'y'. The first assignment to a local variable determines its class. Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: "y"
Hi everybody I have a serious problem and i need your help. i use embedded matlab function in simulink to generate some matrices which i use as input to other bloc on simulink. But i got this error while the simulation is running: Undefined function or variable 'y'. The first assignment to a local variable determines its class. Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: "y" My code is function y = fcn(u) Ap=[0.9580 0 0 0;0 0.9418 0 0;0 0 0.9048 0;0 0 0 0.9277]; Bp=[0.25 0;0.25 0;0 0.5;0 0.5]; Cp=[0.1678 0 0.9516 0;0 0.2329 0 0.2890]; [m1,n1]=size(Cp); [n1,n_in]=size(Bp); A_e=eye(n1+m1,n1+m1); A_e(1:n1,1:n1)=Ap; A_e(n1+1:n1+m1,1:n1)=Cp*Ap; B_e=zeros(n1+m1,n_in); B_e(1:n1,:)=Bp; B_e(n1+1:n1+m1,:)=Cp*Bp; C_e=zeros(m1,n1+m1); C_e(:,n1+1:n1+m1)=eye(m1,m1); y(1:m1,:)=C_e; for kk=1:u-1; y((m1*kk)+1:m1*(kk+1),:)=y(m1*(kk-1)+1:m1*kk,:)*A_e; end thank you so much On 07/16/2014 5:50 AM, AGUEMON wrote: .... .... > ...i got this error while the simulation is > running: > > Undefined function or variable 'y'. The first assignment to a local > variable determines its class. > Function 'Embedded MATLAB Function' (#52.384.385), line 19, column 2: > "y" > .... > C_e(:,n1+1:n1+m1)=eye(m1,m1); > y(1:m1,:)=C_e; > > for kk=1:u-1; > y((m1*kk)+1:m1*(kk+1),:)=y(m1*(kk-1)+1:m1*kk,:)*A_e; .... Never used the em...

Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']?
Is there a simple function to generate a list like ['a', 'b', 'c', ... 'z']? The range() just can generate the numeric list. On Apr 9, 2007, at 3:29 AM, =E4=BA=BA=E8=A8=80=E8=90=BD=E6=97=A5=E6=98=AF=E5= =A4=A9=E6=B6=AF=EF=BC=8C=E6=9C=9B=E6=9E=81=E5=A4=A9=E6=B6=AF=E4=B8=8D=20 =E8=A7=81=E5=AE=B6 wrote: > Is there a simple function to generate a list like ['a', 'b', 'c', ... > 'z']? The range() just can generate the numeric list. import string list(string.lowercase) 人言落日是天涯,望极天涯不见家 schrieb: > Is there a simple function to generate a list like ['a', 'b', 'c', ... > 'z']? The range() just can generate the numeric list. There is: [ chr(i) for i in range(97, 123) ] Thomas T24gQXByIDksIDQ6MzXCoHBtLCBNaWNoYWVsIEJlbnRsZXkgPG1pY2guLi5AamVkaW1pbmR3b3Jr cy5jb20+IHdyb3RlOgo+IE9uIEFwciA5LCAyMDA3LCBhdCAzOjI5IEFNLCDkurroqIDokL3ml6Xm mK/lpKnmtq/vvIzmnJvmnoHlpKnmtq/kuI0KPgo+IOingeWutiB3cm90ZToKPiA+IElzIHRoZXJl IGEgc2ltcGxlIGZ1bmN0aW9uIHRvIGdlbmVyYXRlIGEgbGlzdCBsaWtlIFsnYScsICdiJywgJ2Mn LCAuLi4KPiA+ICd6J10/IMKgIFRoZSByYW5nZSgpIGp1c3QgY2FuIGdlbmVyYXRlIHRoZSBudW1l cmljIGxpc3QuCj4KPiBpbXBvcnQgc3RyaW5nCj4gbGlzdChzdHJpbmcubG93ZXJjYXNlKQoKVGhh bmtzIGEgbG90IQo= T24gQXByIDksIDI6MjnCoGFtLCAi5Lq66KiA6JC95pel5piv5aSp5rav77yM5pyb5p6B5aSp5rav 5LiN6KeB5a62IiA8a2VsdmluLi4uLkBnbWFpbC5jb20+IHdyb3RlOgo+IElzIHRoZXJlIGEgc2lt cGxlIGZ1bmN0aW9uIHRvIGdlbmVyYXRlIGEgbGlzdCBsaWtlIFsnYScsICdiJywg...

I'm a C++ programmer, and Relf's X.CPP is good.
I've developed my hm command (pronounced "home")*, I've modified a Linux kernel mouse driver* to support Microsoft Wireless Optical mice with tilt wheel technology. I use emacs and extend it with LISP. I know my stuff. And with this authority, I have to say that I see nothing wrong with Jeff Relf's X.CPP. Using macros is actually a good idea and is an advanced concept in many programming languages. LISP is a programming language that idealizes the macro. Relf's programming style is quite advanced, and his use of C++ to create a language suited for the application...

Web resources about - MATLAB's SOUND() function in C - comp.sys.mac.programmer.misc

Resources last updated: 3/25/2016 10:05:38 AM