Audio file as array in Android Studio or Eclipse - Android Studio

I don't know if its the right place but I would proceed anyway. In matlab software we can load an audio file in the form of an array and manipulate that values in the array. i have to create an android app which requires a similar kind of thing. Can I load an audio file in the form an array and manipulate the values inside it in an android application. If so please share any tutorial or link that might be of help...

Code:
File[] audioFilesArray = new File[<enter size of array here>];
That will give you an array that holds the object type of "File".
You can then access a specific file by doing
Code:
audioFilesArray[0]
That will return the File object of the first file in the array. Then you can do what you need with that specific file, like play it using the MediaPlayer class.

elesbb said:
Code:
File[] audioFilesArray = new File[<enter size of array here>];
That will give you an array that holds the object type of "File".
You can then access a specific file by doing
Code:
audioFilesArray[0]
That will return the File object of the first file in the array. Then you can do what you need with that specific file, like play it using the MediaPlayer class.
Click to expand...
Click to collapse
How do I assign the values in an audio file to this array? The values that are displayed in matlab when an audio file is loaded. I need to store the samples of audio file in this array. By samples here i meant raw bit of sound which represent the sound intensity in individual channel at an instant of time.

munirshah77 said:
How do I assign the values in an audio file to this array? The values that are displayed in matlab when an audio file is loaded. I need to store the samples of audio file in this array. By samples here i meant raw bit of sound which represent the sound intensity in individual channel at an instant of time.
Click to expand...
Click to collapse
It's really simple. You must convert wav (or another music type) to byte array
Example for one file define like WAY_FILE
Code:
ByteArrayOutputStream out = new ByteArrayOutputStream();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(WAV_FILE));
int read;
byte[] buff = new byte[1024];
while ((read = in.read(buff)) > 0)
{
out.write(buff, 0, read);
}
out.flush();
byte[] audioBytes = out.toByteArray();

munirshah77 said:
How do I assign the values in an audio file to this array? The values that are displayed in matlab when an audio file is loaded. I need to store the samples of audio file in this array. By samples here i meant raw bit of sound which represent the sound intensity in individual channel at an instant of time.
Click to expand...
Click to collapse
I'm not exactly sure what you are trying to do here.. An what I posted previously will give you an array of files. Which you can access and assign using
array[0] where the 0 indicates the first file in that array. To assign it, you would just do
array[0] = new File(<some file location string here>);
Your last sentence, "raw bit of sound which represent the sound intensity in individual channel at an instant of time" i do not understand what you mean. By channel I presume you are referring to left and right audio channels?
How are you obtaining this "raw bit of sound"? If you can convert it to a byte array as the other person posted, then you can write it to a file. But you have to have some sort of input to write or read from.

Related

Changing keyboard sounds

I managed to tweak the registry and add sounds to change the keyboard sounds on my kaiser. I even downloaded some sounds from this site and am using the transformers sound as my default; but when I try and add my own wav files...No Luck!
I encode the wave files to the specifications as the sounds i downloaded and still no luck. Can anyone tell me what settings they use when they create wav files. I use Nero 7 as my audio tool but any info appreciated...Thanks
are you talking about the sliding tone?
if so
HKEY_LOCAL_MACHINE > Software > HTC > SlidingSound
Within this registry folder there will already be 3 folders numbers 0, 1 and 2. Highlighy SlidingSound then click on Edit > New Key. Name the key the next available number. Most likely this will be 3. Now you can either copy the three values from the other listings, or create new ones from scratch by highlighting 3 and clicking Edit > New String Value. They need to look like the following with the left values listed under Name and the right values under Data:
Default - whatever_name_you_want
in - filename1.wav
out - filemane2.wav
make sure you put the files into the windows directory. credit goes to "Bgrngod" on the AT&T forums/
this should do it, check it out: http://forums.wireless.att.com/cng/board/message?board.id=cingular&thread.id=72058
I've done this and it works with the wav files that I downloaded from the internet but the problem is when I try to use my own wave files, it doesn't work. What bit rate should I use or are there requirements that only work?
i'm not sure if there is a bit rate requirement, I've done it to 3 other .wav clip sets all with perfect results. upload your files, i'll give it a try, see if we get the same results.
Cool!!! Thanks.......it's all very odd that the clips of the same kind will not work.....Guess we'll have to wit
One last thing......what audio software do u use???
for clips from movies, i mostly just search the net for them. there are tons out there.
for songs and or audio files i have, i use mp3 cutter trial version and wma cutter trial. it only allows up to 30 sec clips on the trial, but my phone only rings for 25 seconds so any more is just taking up space.
source for the music is either cds, napster, or itunes.
Here's my wav files.....really appreciate this!
Alright i made a cab that does the registry changes and pastes the Default .wav files in the /windows folder. All you need to do is make the 2 sound files that you would like.
Name them:
Custom-in.wav
Custom-out.wav
In the settings menu there will be a new field under the sliding sound icon named "custom". select that and you should be good... ENJOY
http://rapidshare.com/files/79748184/SH4Y_Sliding_Sounds_Configure.cab
The cab worked awesome along with the defaults wav files but my wav files still won't play? Guess I'll try different bit rates......unless someone tries my wavs for feedback
car209los said:
The cab worked awesome along with the defaults wav files but my wav files still won't play? Guess I'll try different bit rates......unless someone tries my wavs for feedback
Click to expand...
Click to collapse
Save them as a regular wav with windows sound recorder... I say a max of 2 seconds...
And the cab comes with e40 saying UGHHHH... hahaha

nexus one video conversion with handbrake

Hi,
Anyone tried using handbrake to do video conversion to mp4 h.264? I'm using 0.9.4 and not having much luck. All i get out is the audio. I can convert to 480x320 resolution on Videora but trying to get 800x480, or something close to that resolution. So i have this video i want to convert and in Handbrake i used the native 720x304 screen size at 24fps. I think i tried 29.997fps too. I am wondering if the bitrate needs to be some specific multiple like 768kbps or 1.5Mbps. Is there a configuration that will work with the Nexus? Thanks in advance.
[update] so i stumbled upon this link that may or may not help.
http://matthodology.com/n1/2010/03/02/convert-movies-for-viewing-on-nexus-one-using-handbrake/
i will try it out tonight and let you folks know.
[update2] hey what do you know, it works! i used the "iPhone & iPod Touch" preset and it looked pretty good. exciting! need to experiment with more videos. follow the instructions in the link and make sure you adjust the width appropriately. definitely don't try a resolution that is over the source resolution, that's just wasteful! hehe
I know the physical sizes of the iPod/iTouch are about the same, but isn't the resolution 2 times less?
Nexus One Resolution: 800 x 400 = 320,000 Pixels
Iphone Resolution: 480 x 320 = 153,600 Pixels
2.08 times less?
It would seem you are not getting near the resolution the phone is capable of.
my problem was Handbrake was saving everything as .m4a. Change your extension to .mp4 if you haven't already done so.
ccunningham83 said:
I know the physical sizes of the iPod/iTouch are about the same, but isn't the resolution 2 times less?
Nexus One Resolution: 800 x 400 = 320,000 Pixels
Iphone Resolution: 480 x 320 = 153,600 Pixels
2.08 times less?
It would seem you are not getting near the resolution the phone is capable of.
Click to expand...
Click to collapse
somehow that particular preset works, you can adjust the output resolution in the first tab. from what i'm seeing it seems like it's working. i will use a media tool to check the resultant file's resolution tonight. good point though.
The Windows Mobile part of the forum has a great application that has thus far worked great for me.
HD Encoder by projection:
http://forum.xda-developers.com/showthread.php?t=467112
I actually just got handbrake set up doing video conversions for the Nexus, but it's at home. If I remember correctly, I used the iPod settings, then changed a couple of values (namely setting the width to 800 by default and letting it keep aspect ratio) and set a preset. Looks fantastic on the Nexus, I'll try to see if I can export the preset somehow when I get home and send it your way.
Swervo said:
I'll try to see if I can export the preset somehow when I get home and send it your way.
Click to expand...
Click to collapse
Looking forward to this
try format factory... it has a preset for the N1
Handbrake is great , has alot of options, as usual it is only good if you know what you are doing, so we need a preset that WORKS.
right now I'm testing HD Encoder by projection, runnig it on Ubuntu usin Wine 1.2 Beta , well it has ceashed ... will test more.
The good thing is you have just 3 options ... so it's easy to use
OrganizedFellow said:
Looking forward to this
Click to expand...
Click to collapse
Rats, I can't seem to find a way to export a preset, so I'll just try to type out what I set. I know I started with the iPod preset:
On Picture, I have Width = 800, then click "Keep Aspect Ratio" and let it populate height. Anamorphic set to "None", Cropping set to "Automatic".
On Video Filters, everything is set to Off and unchecked.
On Video, Video Codec is H.264 (x264), Framerate is "Same as source", Avg. Bitrate is checked with the value of "1500"
On Audio, the one track is set as Source: Automatic, Audio Codec: AAC (faac), Mixdown: Stereo, Samplerate: 48, Bitrate: 128, DRC: 0.0.
Nothing special for Subtitles or Chapters
Advanced I've got:
Reference Frames: 1
B-Frames: 0
Motion Estimation Method: Uneven Multi-Hexagon
Subpixel Motion Estimation: 6
Motion Estimation Range: Default (16)
Analysis: All
8x8 DCT: Unchecked
CABAC Entropy Coding: Unchecked
Psychovisual Rate Distortion: Greyed, all the way left.
No Fast-P-Skip: Checked
No DCT-Decimate: Unchecked
Deblocking: Both on Default.
Hope that helps!
JHaste said:
try format factory... it has a preset for the N1
Click to expand...
Click to collapse
how do you like that converter so far? how long does it take you to convert a full movie like district 9? i'm using aimersoft.com and they also have a N1 preset and add subtitles from srt files. you guys can get it free via torrent
Nexus One Handbrake Preset
Swervo said:
Rats, I can't seem to find a way to export a preset, so I'll just try to type out what I set. I know I started with the iPod preset:
On Picture, I have Width = 800, then click "Keep Aspect Ratio" and let it populate height. Anamorphic set to "None", Cropping set to "Automatic".
On Video Filters, everything is set to Off and unchecked.
On Video, Video Codec is H.264 (x264), Framerate is "Same as source", Avg. Bitrate is checked with the value of "1500"
On Audio, the one track is set as Source: Automatic, Audio Codec: AAC (faac), Mixdown: Stereo, Samplerate: 48, Bitrate: 128, DRC: 0.0.
Nothing special for Subtitles or Chapters
Advanced I've got:
Reference Frames: 1
B-Frames: 0
Motion Estimation Method: Uneven Multi-Hexagon
Subpixel Motion Estimation: 6
Motion Estimation Range: Default (16)
Analysis: All
8x8 DCT: Unchecked
CABAC Entropy Coding: Unchecked
Psychovisual Rate Distortion: Greyed, all the way left.
No Fast-P-Skip: Checked
No DCT-Decimate: Unchecked
Deblocking: Both on Default.
Hope that helps!
Click to expand...
Click to collapse
Thanks for this.
I am able to export presets, so after I'm done converting "Fight Club", if the settings worked, I'll update my reply with the preset attached.
[edit]
15 hours to encode...fuxit.
The preset (using Swervo's info in the above post) is attached. Remove the .txt extension.
Just downloaded and installed Format Factory... where's the Nexus One preset?! Under Google, there are two for a device called GX... neither with the correct resolution.
uansari1 said:
Just downloaded and installed Format Factory... where's the Nexus One preset?! Under Google, there are two for a device called GX... neither with the correct resolution.
Click to expand...
Click to collapse
Did you find the nexus preset...I can't find it myself
I just use the iPhone/iPod Touch setting, the resolution is lower, but it looks fine and keeps the file size down. I've converted seasons of TV shows and it works great
icegad said:
Did you find the nexus preset...I can't find it myself
Click to expand...
Click to collapse
Yeah... go to HTC/Dopod 800X480 AVC. Default settings work perfectly.
How long does converting a 700mb video in format factory take.its been 3 hrs and I'm at 72%. Is this normal?
I use to have a BB and I used this guide:
http://forums.crackberry.com/f135/dvd-storm-walkthrough-pictures-107961/
It worked on my BB and it works flawlessly on my N1.
icegad said:
How long does converting a 700mb video in format factory take.its been 3 hrs and I'm at 72%. Is this normal?
Click to expand...
Click to collapse
It depends on your computer's specs... but even on my laptop, which is running a core2 duo with 3gb of ram, it takes about 60% of the time of the length of the movie, or maybe a little less.
lol, takes me 7-12 minutes to encode a 2hr movie to 80% of original size

Clone DataInputStream

Hello all,
I am creating an app for Android and a I need to save in two different variables the same part (64B) of the stream. How can I clone the stream in order to for save in two different variables the same part of stream? Otherwise, how can I position the pointer in the stream in order to read twice the same part of the stream?
I am using this:
DataInputStream in;
in.read(data,0 , numBytesRead);
Thanks so much,

How can I get a string title, artist for what my Chromecast is playing?

Hello everyone!
I like to work with LED signs and other fun display technologies and as much as I love my chromecast audio, sadly it has no way of displaying what it is currently playing. Now I know that this information must be somewhat publicly available because the Chromecast app for android can show me what content is playing from Spotify, even if the session is initiated by another client as you can see here:
(Well I can't post images because I'm a new user, use your imagination to see that I can start playing something from Spotify on another device and I'm still able to get cover art, title and artist name here in this native android chromecast app)
Anyway, I'm having trouble devising a way to fetch this information from the Chromecast, I'd really love to send it to some digital signage so I can keep tabs on what's playing, even if that's just say - a raspberry pi with an old VFD attached. So far I was able to use the node chromecast-cli to grab some rudimentary information from the device when it's playing stuff from Spotify. Here's what I get:
Code:
Komputer$ node chromecast-cli.js --host [IPaddress] status
{ applications:
[ { appId: 'CC32E753',
displayName: 'Spotify',
isIdleScreen: false,
namespaces: [Object],
sessionId: 'C6A14255-0DE0-44DE-9A06-BC9D07D33A53',
statusText: 'Spotify',
transportId: 'web-3' } ],
volume:
{ controlType: 'attenuation',
level: 0.7843137383460999,
muted: false,
stepInterval: 0.05000000074505806 } }
so um, most of this status information is painfully redundant, displayName and StatusText are both just 'Spotify' and right now I can't see any useful information about what's playing. So I'm left to assume that the namespaces object is encoded as JSON and potentially contains what I'm looking for, but I'm not sure as to how to actually get it and extract it and put it to good use - or I could be totally wrong and that contains nothing useful. Go figure, but either way I suppose someone here might have the experience needed here to shake this information out of the thing. This might only be pertinent to Spotify, but that's what I use 90% of the time so it's good either way, there might be a more generic string that can be fetched for whatever is playing. Any help would be greatly appreciated!
Thanks in advance!
I found the other library call castnow (github.com/xat/castnow) does the same thing as chromecast-cli, but it will showing Chromecast's current status, which includes duration, playhead time and the source of current playing. So I think you can make your own hook based on this library. Hope that helps.
ajhsu said:
I found the other library call castnow (github.com/xat/castnow) does the same thing as chromecast-cli, but it will showing Chromecast's current status, which includes duration, playhead time and the source of current playing. So I think you can make your own hook based on this library. Hope that helps.
Click to expand...
Click to collapse
Okay I'll look into it, hopefully it's a bit easier to query than the Python tool I've been using lately.
Thanks!

Getting a 3rd party audio player to stop when switching modes.. use MTC Manager ?

Hello all,
I have some questions, that I hope people can help with.
I am running the newest Malaysk 4.4.4 rom on a RK3188 800x600 unit.
I want to use the Musicolet Music Player as the media player.
(Hardware buttons on the head unit are configured via MTC-Keys and work fine)
The problem: This 3rd party media player keeps running when switching to MTC microntek radio.
This occurs even if the app is selected as the media player. (likely due to Musicolet not being directly supported)
Based on what I have read (portion below), @MVG-V70 's MTC Manager module will allow you to customize it to switch between the different modes in a MTCB.
1) The docs, refer to "When the MODE mutton is pressed". I assume this means ANY of the mod buttons on a MTCB ( examples: DVD/NAVI/BAND...) ?
2) The docs show how each mod is configured in the mode.ini file (See portion below) I want to use the Musicolet music player.
How do I determine all the intents info needed ?
The Package manager app I am using shows the following:
SERVICES
in.krosbits.musicolet.MusicService
ACTIVITIES
in.krosbits.musicolet.MusicActivity
How do i determine what intents are needed to send a stop/start to the Musicolet Media Player?
Is there a different app that will list them ?
Thanks for any help !
LRail
NOTE: the mode.ini docs below are not my actual settings
----------------------------------------------------------------
Portion of MTC Manager docs below
Code:
Programs are switched sequentially one after the other.
For correct sound switching, the applications used must be managed (play / pause) programmatically via intents.
If the player does not support the beginning and stopping of playback by external intents, then it is necessary to switch the sound manually.
When the MODE button is pressed, the active application is searched for in the running list. Next, the application is sent a command (configurable in mode.ini) to close or pause the audio stream.
After that, the default activation for the next application is launched and the application is sent a command to start playback (also configured in mode.ini)
#mode.ini
# list of applications to switch, package names must be listed
[apps]
# established radio
com.microntek.radio
# PowerAmp
com.maxmpz.audioplayer
# staff
com.microntek.music
# PCRadio
com.maxxt.pcradio
# staff DVD
com.microntek. dvd
Code:
# disabling playback in PowerAmp
[com.maxmpz.audioplayer: stop]
# service name
service = com.maxmpz.audioplayer.player.PlayerService
#
intent name intent = com.maxmpz.audioplayer .API_COMMAND
# action startService
send = service
# parameter name
extra = cmd
# parameter type
extra_type = int
# value
value = 2

Categories

Resources