sound in APL

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

sound in APL

Postby Stu on Mon Jun 27, 2016 4:24 am

Is there some facility in, or available to, Dyalog APL that can play a vector of sound samples? I tried to use the Workspace Explorer to see what might be in .NET, but I haven't figured out how to use it yet.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: sound in APL

Postby PGilbert on Tue Jun 28, 2016 2:50 pm

The following is working for me for playing a file:

Code: Select all
      ⎕USING ← 'System.Windows.Media,WPF/PresentationCore.dll' 'System,System.dll'

      mp  ← ⎕NEW MediaPlayer
      uri ← ⎕NEW Uri (⊂'d:\kalimba.mp3')
      mp.Open uri
      mp.Play
      mp.Stop
User avatar
PGilbert
 
Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: sound in APL

Postby Stu on Tue Jun 28, 2016 4:04 pm

This is helpful, but I still have some questions:

1) Is there a facility for converting a vector into a file in some standard audio format, like .wav or .mp3? I want to generate my own sound samples rather than use some pre-recorded file.

2) Where is the documentation that describes how you used the media player?
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: sound in APL

Postby PGilbert on Tue Jun 28, 2016 6:32 pm

I have found that link for the examples.

For the other question I don't understand, would you like to save a sound file (like mp3) in the workspace and play it later or define yourself a vector of numbers that represent your music and save it as a mp3 (in the WS or disk) ?
User avatar
PGilbert
 
Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: sound in APL

Postby Stu on Tue Jun 28, 2016 10:31 pm

What I would like to do is compute vectors containing samples of different kinds of sounds and then play them directly without converting the vectors to some audio file format. If you're familiar with Matlab, you'll recognize that I'm interested in the equivalent of sound() and soundsc(). I already have a "toolbox" of audio generating and processing functions that I'd like to translate into APL. I just need the sound player.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: sound in APL

Postby Stu on Fri Jul 01, 2016 12:05 am

I'm still searching for a way to play my computed sounds in Dyalog. There are apparently .NET classes to allow this, but I can't find them. In the Dyalog .NET guide it says:

"To enable the display of Metadata in the Workspace Explorer, you must have the Type
Libraries option of the View menu checked."

My View menu doesn't have this option (it's mostly about icons). So what do I need to do to be able to browse the .NET classes?
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: sound in APL

Postby Vince|Dyalog on Fri Jul 01, 2016 9:05 am

Hi Stu,

The advice about the View menu in our .NET interface documentation is wrong, and I'll tell our docs team about this.

In the Workspace Explorer, you can right click on Metadata.

For a example, you could choose Load and load the following assembly c:\windows\Microsoft.NET\Framework\v4.0.30319\system.dll

I am not sure if browsing the metadata in this way will be of much help. You may still need to continue searching the internet to find any references to an OLE or .NET tool which does what you need.

Regards,

Vince
Vince|Dyalog
 
Posts: 335
Joined: Wed Oct 01, 2008 9:39 am

Re: sound in APL

Postby PGilbert on Fri Jul 01, 2016 12:04 pm

Looks like that Mathlab has its own format for storing/playing sound files. If you could convert them to .wav files then it is possible to store them in the workspace and play them with SoundPlayer as a stream without saving any intermediary file to disk.

I could prepare some examples of how to store a .wav file in the WS and how to play it back as a stream if this is helpful but you would need to convert your Mathlab sound files to .wav files which I don't know how to do.

There is nothing in Dyalog APL that is native to playing/storing sounds so we have to use Windows.
User avatar
PGilbert
 
Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: sound in APL

Postby Stu on Fri Jul 01, 2016 4:54 pm

I know how to make a .wav file in C and C++. .wav files are all about byte counts, so I still have to master that aspect of Dyalog. I'll get back to you on how to play the files once I'm able to make them.

It would be nice if Dyalog had something like Matlab's sound() function. I'm sure it's based on the underlying Windows audio player, but all the Matlab programmer needs to do is plug in the name of the vector (and, optionally, the sample rate), i.e., sound(samples, samplerate). I'm not a real fan of Matlab. Its implementation of the array programming paradigm is very weak compared with APL's, but it does make life easy in the specific area of creating and playing sound.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: sound in APL

Postby Stu on Sun Jul 03, 2016 2:31 am

Making a .wav file is more difficult than I'd thought. I have to be able write into the file some character strings that occupy exactly 4 bytes each, and also some little-endian unsigned ints that occupy 2 or 4 bytes each depending on the particular data item. The audio sample data has to end on an even byte boundary. I don't know how to do any of this in Dyalog, so I really could use some help.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Next

Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest