开发者

Any way to create an arbitrary tone with Basic4android?

开发者 https://www.devze.com 2023-04-10 09:29 出处:网络
Is there any way with Basic4Android to make it emit a sound of arbitrary frequency (meaning, I don\'t want to have pre-recorded sound files) and duration?

Is there any way with Basic4Android to make it emit a sound of arbitrary frequency (meaning, I don't want to have pre-recorded sound files) and duration?

In some "traditional" Basic languages this would be done via e.g. a BEEP command followed by the desired frequency and duration.

Basic4Android doesn't seem to support any equivalent command.

I am looking for this feature in order to program a Morse Code generating app and for this purpose I need to stay flexible regarding the audio frequency tone (must be user selectable) between e.g. 500Hz and lets say 1000 Hz as well as variable duration in milliseconds (in order to be able to generate variable user selectable speeds of the morse code dashes and dots and silent breaks inbetween)...

It's simply not practical or near to impossible to do this with prerecorded WAV's or you would end up in a huge WAV collection for all frequency/speed combinations.

It seems to be possible in Android to do so, see example here: http://marblemice.blogspot.com/2010/...n-android.html

As far as I can interpret this code it calculates a sine wave tone "on the fly" at the desired frequency into a buffer array and uses that buffer data to generate and play it as a PCM stream.

Since above code seems to b开发者_开发问答e quite simple I wonder if a clever Java programming guy would come up with a simple Basic4Android "Tone Generator" library which others could use for this purpose?

Unfortunately, I am only an old fashioned VisualBasic guy and making my first steps with Basic4Android...for creating my own library my skills are simply too lousy.


The Audio library was updated and you can now use the Beeper object to play "beep" sounds.

Dim b As Beeper
b.Initialize(300, 500) '300 milliseconds, 500hz
b.Beep

Updated library link


This is definitely possible to do on Android, in a java-based application. I don't know if Basic4Android can do this "natively" (I'd never heard of Basic4Android before this), but it appears that you can create libraries in java that can then be accessed by Basic4Android, so it would be theoretically possible to create a java library that does this and then call it from your B4A app.

However, since this would entail learning some java and the Android plugin for Eclipse anyway, maybe you should just take the plunge and learn java for Android? I'm a long-term Visual Basic guy myself (started in 1995), and it wasn't really that difficult to transition to C# and thence to java.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号