|
radio42
Posts: 4030
|
 |
« Reply #540 on: 6 Sep '12 - 12:26 » |
Quote
|
As you are referencing the Bass.Net.iphone version are you sure to also use the special iphone version if the native bass lib?
|
|
|
|
|
Logged
|
|
|
|
|
Konstantin
Posts: 8
|
 |
« Reply #541 on: 6 Sep '12 - 12:35 » |
Quote
|
radio42 thank you for your answer.
As I understood, Bass.Net.iPhone.dll - is just C# wrapper for unmanaged bass.dll(so I add wrapper as reference and bass.dll into output folder)? Or I need any special bass.dll for it?
(I downloaded, Bass24.Net.zip, installed it and took bass.net.iphone.dll from there - I didn't see any special version of bass.dll there? And also it isn't giving the answer, why console application doesn't work)
|
|
|
|
« Last Edit: 6 Sep '12 - 13:02 by Konstantin »
|
Logged
|
|
|
|
|
|
|
Konstantin
Posts: 8
|
 |
« Reply #543 on: 7 Sep '12 - 10:27 » |
Quote
|
When using ChannelSync for reading Meta tags, my app crash on the iPhone device but works just fine in the simulator. I set sync like this: mySync = new SYNCPROC(MetaSync); Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_META, 0, mySync, IntPtr.Zero);
and get meta data like this: private void MetaSync(int handle, int channel, int data, IntPtr user) { TAG_INFO tags = new TAG_INFO();
if (tags.UpdateFromMETA(Bass.BASS_ChannelGetTags(_stream, BASSTag.BASS_TAG_META), false, true)) { _NetStreamEventArgs.Artist = tags.artist; _NetStreamEventArgs.Title = tags.title; } }
The app crash on "Bass.BASS_ChannelSetSync", here is the debug info I get from Monotouch Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method '(wrapper native-to-managed) CasterPlay.AudioEngine:MetaSync (int,int,int,intptr)' while running with --aot-only.
at (wrapper managed-to-native) Un4seen.Bass.Bass:BASS_ChannelSetSync (int,Un4seen.Bass.BASSSync,long,Un4seen.Bass.SYNCPROC,intptr)
I can read tags "manually" like this (but then I need a timer to pull the data.. TAG_INFO _tagInfo = new TAG_INFO(URL);
if (BassTags.BASS_TAG_GetFromURL(_stream, _tagInfo)) {
_NetStreamEventArgs.Artist = _tagInfo.artist; _NetStreamEventArgs.Title = _tagInfo.title; }
Is is Bass, Bass.Net or me...? /Ken Hello again. Faced the same problem. Ken, did you find a solution? Application crashed each time I try to use _soundEndedHandler = new SYNCPROC(soundFinished); Bass.BASS_ChannelSetSync(_stream,BASSSync.BASS_SYNC_END,0, _soundEndedHandler ,IntPtr.Zero); or _recordingCompletedHandler = new RECORDPROC(recordingFinished); _record = Bass.BASS_RecordStart(44100, 1, BASSFlag.BASS_SAMPLE_FLOAT, _recordingCompletedHandler, IntPtr.Zero); Can anyone write small tutorial how to work it out? Thanks a lot, /Konstantin
|
|
|
|
|
Logged
|
|
|
|
|
tr1stan
Posts: 10
|
 |
« Reply #544 on: 7 Sep '12 - 14:31 » |
Quote
|
Hi all,
I'm looking for a method to do a BPM detection on iPhone, but I'm new to Bass and it's very confused to get started.
1. Which library shoud I use? bass or bass_fx, or both? 2. Is bass bpm detection support the m4a format? 3. Where can I find a example code of BPM detection?
Thanks tr1stan
|
|
|
|
« Last Edit: 7 Sep '12 - 14:54 by tr1stan »
|
Logged
|
|
|
|
|
Ian @ un4seen
Administrator
Posts: 15366
|
 |
« Reply #545 on: 7 Sep '12 - 17:28 » |
Quote
|
I'm looking for a method to do a BPM detection on iPhone, but I'm new to Bass and it's very confused to get started.
1. Which library shoud I use? bass or bass_fx, or both?
You would need both BASS and the BASS_FX add-on. 2. Is bass bpm detection support the m4a format?
Yes, the BPM detection works independently of the audio file format. 3. Where can I find a example code of BPM detection?
I'm not sure if there is currently any iOS-specific example code available for that, but the core BASS and BASS_FX calls will be the same on any platform, so you could take a look at the BPM example that comes in the Win32 BASS_FX package for some ideas. Basically, you would use BASS_FX_BPM_CallbackSet to detect the BPM during playback, something like this... stream=BASS_StreamCreateFile(FALSE, filename, 0, 0, 0); // create a stream from an audio file BASS_FX_BPM_CallbackSet(stream, BPMCallback, 5, 0, BASS_FX_BPM_MULT2, 0); // set a BPM detection callback on the stream BASS_ChannelPlay(stream, FALSE); // start the stream
...
void CALLBACK BPMCallback(DWORD handle, float bpm, void *user) { // do something with the "bpm" value here }
If you want to detect the BPM without playback, you would make the stream a "decoding channel" via the BASS_STREAM_DECODE flag and then use BASS_FX_BPM_DecodeGet.
|
|
|
|
|
Logged
|
|
|
|
|
tr1stan
Posts: 10
|
 |
« Reply #546 on: 7 Sep '12 - 17:59 » |
Quote
|
Thanks for your reply Ian. I'm not intended to detect bpm during playback, so I will just use BPM_DecodeGet instead. Would you please post another snippet using the DecodeGet method? That would be helpful. And how about the installation? Do I need to import all static libraries packed with Bass 2.4 in order to use bass_fx? Currently I added libbass.a, libbass_fx.a, bass.h and bass_fx.h to my xcode project, but the complier reports 20 errors /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:36:1: error: unknown type name 'DWORD' DWORD BASS_FXDEF(BASS_FX_GetVersion)(); ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:36:18: error: expected ';' after top level declarator DWORD BASS_FXDEF(BASS_FX_GetVersion)(); ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:25:32: note: expanded from macro 'BASS_FXDEF' #define BASS_FXDEF(f) WINAPI f ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:312:1: error: unknown type name 'HSTREAM' HSTREAM BASS_FXDEF(BASS_FX_TempoCreate)(DWORD chan, DWORD flags); ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:312:20: error: expected ';' after top level declarator HSTREAM BASS_FXDEF(BASS_FX_TempoCreate)(DWORD chan, DWORD flags); ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:25:32: note: expanded from macro 'BASS_FXDEF' #define BASS_FXDEF(f) WINAPI f ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:313:1: error: unknown type name 'DWORD' DWORD BASS_FXDEF(BASS_FX_TempoGetSource)(HSTREAM chan);
...
|
|
|
|
« Last Edit: 9 Sep '12 - 04:28 by tr1stan »
|
Logged
|
|
|
|
|
tr1stan
Posts: 10
|
 |
« Reply #547 on: 10 Sep '12 - 09:04 » |
Quote
|
Thanks for your reply Ian. I'm not intended to detect bpm during playback, so I will just use BPM_DecodeGet instead. Would you please post another snippet using the DecodeGet method? That would be helpful. And how about the installation? Do I need to import all static libraries packed with Bass 2.4 in order to use bass_fx? Currently I added libbass.a, libbass_fx.a, bass.h and bass_fx.h to my xcode project, but the complier reports 20 errors /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:36:1: error: unknown type name 'DWORD' DWORD BASS_FXDEF(BASS_FX_GetVersion)(); ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:36:18: error: expected ';' after top level declarator DWORD BASS_FXDEF(BASS_FX_GetVersion)(); ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:25:32: note: expanded from macro 'BASS_FXDEF' #define BASS_FXDEF(f) WINAPI f ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:312:1: error: unknown type name 'HSTREAM' HSTREAM BASS_FXDEF(BASS_FX_TempoCreate)(DWORD chan, DWORD flags); ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:312:20: error: expected ';' after top level declarator HSTREAM BASS_FXDEF(BASS_FX_TempoCreate)(DWORD chan, DWORD flags); ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:25:32: note: expanded from macro 'BASS_FXDEF' #define BASS_FXDEF(f) WINAPI f ^ /b62/../BOF 62/Assets/Editor/MediaPlayer/../../../../b62/bass_fx.h:313:1: error: unknown type name 'DWORD' DWORD BASS_FXDEF(BASS_FX_TempoGetSource)(HSTREAM chan);
...
I figured it out myself. It was me forgot to add bass.h header to bass_fx.h
|
|
|
|
|
Logged
|
|
|
|
|
Ian @ un4seen
Administrator
Posts: 15366
|
 |
« Reply #548 on: 10 Sep '12 - 15:11 » |
Quote
|
I'm not intended to detect bpm during playback, so I will just use BPM_DecodeGet instead. Would you please post another snippet using the DecodeGet method? That would be helpful.
The main difference when using BASS_FX_BPM_DecodeGet is that the source stream needs to be a "decoding channel" (using the BASS_STREAM_DECODE flag). stream=BASS_StreamCreateFile(FALSE, filename, 0, 0, BASS_STREAM_DECODE); // create a "decoding channel" from an audio file bpm=BASS_FX_BPM_DecodeGet(stream, 30, 60, 0, BASS_FX_BPM_MULT2, NULL, 0); // get the BPM between 30s and 60s
And how about the installation? Do I need to import all static libraries packed with Bass 2.4 in order to use bass_fx?
You would only need the BASS (LIBBASS.A) and BASS_FX (LIBBASS_FX.A) libraries, although adding the others to your project shouldn't be a problem as the linker should only include libraries that are actually used in the app. Application crashed each time I try to use _soundEndedHandler = new SYNCPROC(soundFinished); Bass.BASS_ChannelSetSync(_stream,BASSSync.BASS_SYNC_END,0, _soundEndedHandler ,IntPtr.Zero); or _recordingCompletedHandler = new RECORDPROC(recordingFinished); _record = Bass.BASS_RecordStart(44100, 1, BASSFlag.BASS_SAMPLE_FLOAT, _recordingCompletedHandler, IntPtr.Zero); Can anyone write small tutorial how to work it out? Is it crashing within the BASS_ChannelSetSync/BASS_RecordStart call or does it crash after the call has returned? If it's after the call has returned, then I would guess that the problem is related to the callback function. One thing to look out for is the callback function delegate being garbage collected. Please see the BASS.Net documentation (eg. the "Interoperating with Unmanaged Code" section) for details on that.
|
|
|
|
|
Logged
|
|
|
|
|
Konstantin
Posts: 8
|
 |
« Reply #549 on: 11 Sep '12 - 08:37 » |
Quote
|
Ian @ un4seenThanks for your reply. Is it crashing within the BASS_ChannelSetSync/BASS_RecordStart call or does it crash after the call has returned It's crashing immediately when you call it. For example such code also crashing: _record = Bass.BASS_RecordStart(44100, 1, BASSFlag.BASS_SAMPLE_FLOAT, new RECORDPROC((handle, buffer, length, user)=> { return 0; }), IntPtr.Zero); And I use delegate in a "right way"(according http://www.bass.radio42.com/help/html/9b9af3f1-f0dd-42e8-898a-ed607b9d0f60.htm) to protect it from GC.. 
|
|
|
|
« Last Edit: 11 Sep '12 - 08:45 by Konstantin »
|
Logged
|
|
|
|
|
Konstantin
Posts: 8
|
 |
« Reply #550 on: 11 Sep '12 - 09:26 » |
Quote
|
StackOverflow rocks  For someone, who will faced the same problem: Add the MonoPInvokeCallback attribute to your recordingHandler function. Note that you also need to make the function static. [MonoPInvokeCallback ()] private static int recordingHandler (int handle, IntPtr buffer, int length, IntPtr user) { // ... } It works!
|
|
|
|
|
Logged
|
|
|
|
|
radio42
Posts: 4030
|
 |
« Reply #551 on: 11 Sep '12 - 10:25 » |
Quote
|
take a look here: http://docs.xamarin.com/ios/about/limitationsReverse Callbacks: In standard Mono it is possible to pass C# delegate instances to unmanaged code in lieu of a function pointer. The runtime would typically transform those function pointers into a small thunk that allows unmanaged code to call back into managed code (like in your code example!). In Mono these bridges are implemented by the Just-in-Time compiler. When using the ahead-of-time compiler required by the iPhone there are two important limitations at this point: You must flag all of your callback methods with the MonoPInvokeCallbackAttribute The methods have to be static methods, there is no support for instance methods. It is a limitation of the monoTouch for iPhone AOT compiler! The linked documentation is provided for the regulat .Net version, not the special iPhone version! So you code might look something like this: [MonoPInvokeCallback (typeof (RECORDPROC))] private static bool MyRecoring(int handle, IntPtr buffer, int length, IntPtr user) { ... }
|
|
|
|
|
Logged
|
|
|
|
|
Konstantin
Posts: 8
|
 |
« Reply #552 on: 11 Sep '12 - 15:56 » |
Quote
|
Thank you, radio42Next stupied question: I finally record sound on my iPhone, callback with byte[] fires several times per second. So I have to transform it into more friendly form. I took speex library for it( http://nspeex.codeplex.com/). When I start recording, I create a file sample.spx and create instance of OggSpeexWriter. Each time Callback fires - I encode data and after that trying to write in into file sample.spx via OggSpeexWriter. Is it correct actions order? Any logical mistakes? In result now I have a sample.spx file, that VLC can't play(length of audio shows 0:00). Or, probably, there's another way of saving binary data into audio format? public void StartRecording() { Bass.BASS_RecordInit(-1); _recordingHandler = new RECORDPROC(recordingHandler); _record = Bass.BASS_RecordStart(44100, 1, BASSFlag.BASS_SAMPLE_8BITS, _recordingHandler, IntPtr.Zero);
Bass.BASS_ChannelPlay(_record, false);
string path = Environment.GetFolderPath (Environment.SpecialFolder.Personal); string filePath = Path.Combine(path, "sample.spx"); speexWriter.Open(filePath); speexWriter.WriteHeader("Recording"); }
public void StopRecording () { Bass.BASS_ChannelStop (_record); speexWriter.Close (); }
[MonoPInvokeCallback (typeof (RECORDPROC))] private static int recordingHandler (int handle, IntPtr buffer, int length, IntPtr user) { var buff = new byte[length]; Marshal.Copy(buffer, buff, 0, length);
_recbuffer.AddRange(buff); _byteswritten += length; if (_byteswritten >= BITRATE && _recbuffer != null) { while (_byteswritten>=BITRATE) { //speexWriter.WritePacket(_recbuffer.GetRange(0,BITRATE).ToArray(),0,BITRATE); _byteswritten -= BITRATE; Encode(_recbuffer, BITRATE); _recbuffer.RemoveRange(0,BITRATE); } } return 1; }
private static void Encode(List<byte> buff, int length) { short[] data = new short[length / 2];
int sampleIndex = 0; var bufferArray = buff.ToArray(); for (int index = 0; index < length; index += 2, sampleIndex++) data[sampleIndex] = BitConverter.ToInt16(bufferArray, index);
var encodedData = new byte[length]; var encodedBytes = encoder.Encode(data, 0, sampleIndex, encodedData, 0, length); if (encodedBytes != 0) speexWriter.WritePacket(encodedData, 0, BITRATE); } Thank you and sorry for stupied questions /Konstantin
|
|
|
|
|
Logged
|
|
|
|
|
radio42
Posts: 4030
|
 |
« Reply #553 on: 11 Sep '12 - 16:05 » |
Quote
|
I am not really familiar with the SpeexWriter.
|
|
|
|
|
Logged
|
|
|
|
|
Konstantin
Posts: 8
|
 |
« Reply #554 on: 11 Sep '12 - 16:09 » |
Quote
|
Maybe you can suggest any alternatives? (how to transform byte[] into playable file)
|
|
|
|
|
Logged
|
|
|
|
|
tr1stan
Posts: 10
|
 |
« Reply #555 on: 12 Sep '12 - 10:31 » |
Quote
|
Hi, here's my weekly question  . I tried to get the file BPM and it works... sometimes. I can get most of my mp3 files BPM but for some reason there are a few files I can't. Here's the code void CALLBACK getBpmProc(DWORD chan, float percent) { percent = percent; }
- (void) decodeBPM { HSTREAM bpmChan = BASS_StreamCreateFile(0, [[self filePath] UTF8String], 0, 0, BASS_SAMPLE_FLOAT | BASS_STREAM_PRESCAN | BASS_STREAM_DECODE); if (bpmChan == 0) NSLog(@"BPM CHAN FAILED %d", BASS_ErrorGetCode()); double endSec = BASS_ChannelBytes2Seconds(bpmChan, BASS_ChannelGetLength(bpmChan, BASS_POS_BYTE)); float bpm = BASS_FX_BPM_DecodeGet(bpmChan, 0.0, endSec, 0, BASS_FX_BPM_MULT2, (BPMPROCESSPROC *)&getBpmProc); BPMFile = bpm; currentBPM = bpm; // NSLog(@"BPM decode BPM %f", bpm); BOOL val = BASS_FX_BPM_Free(bpmChan); if (val == FALSE) NSLog(@"BPM FREE FAILED %d", BASS_ErrorGetCode()); }
What could be the error since it works for other files? Another question: It seems that when I put some FX effect like phaser or whatever it always increase the volume. How can I disable this increasing? I've got exactly the same problem. How do you resolve that eventually?
|
|
|
|
|
Logged
|
|
|
|
|
mix1009
Posts: 5
|
 |
« Reply #556 on: 13 Sep '12 - 15:21 » |
Quote
|
Please provide armv7s architecture support for the iOS libraries.
Thank you.
|
|
|
|
« Last Edit: 13 Sep '12 - 18:12 by mix1009 »
|
Logged
|
|
|
|
|
AnthonyM
Posts: 47
|
 |
« Reply #557 on: 14 Sep '12 - 07:13 » |
Quote
|
The iPhone 5 uses ARMv7s. Please add this to BASS, BASS_FX, etc. Thanks Ian 
|
|
|
|
|
Logged
|
|
|
|
|
tr1stan
Posts: 10
|
 |
« Reply #558 on: 14 Sep '12 - 15:29 » |
Quote
|
Before Ian update the library we still can use armv7 architecture to build an app for iPhone 5. I think iPhone 5 will be compatible to armv7 architecture, just don't use the latest performance optimizations it offers.
|
|
|
|
|
Logged
|
|
|
|
|
Ian @ un4seen
Administrator
Posts: 15366
|
 |
« Reply #559 on: 14 Sep '12 - 17:40 » |
Quote
|
I gather armv7s support is introduced in Xcode 4.5 & iOS 6, which are currently beta/pre-release. It looks like that stuff also removes support for the armv6 architecture, so a bit of fiddling will be needed to still include support for that in the BASS libraries. I'll look into this next week, and hopefully be back with some updated libraries.
|
|
|
|
|
Logged
|
|
|
|
|