0

私は現在、csharp を使用して Xamarin スタジオで Android 用の音楽アプリを作成しています。私は単純なシンセサイザー アプリを作成していますが、現在 csharp で GetMinBufferSize メソッドを使用しています。

Xamarin.Android のドキュメントでは、GetMinBufferSize メソッドの次の構文が提供されています (リンクは次のとおりです: xamarin API audiotrack documentation :

[Android.Runtime.Register("getMinBufferSize", "(III)I", "")]
public static int GetMinBufferSize (int sampleRateInHz, 
[Android.Runtime.GeneratedEnum] ChannelOut channelConfig, 
[Android.Runtime.GeneratedEnum] Encoding audioFormat)

public static int getMinBufferSize (int sampleRateInHz、int channelConfig、int audioFormat)

私が理解していないのは、これらのものとは何か、そしてそれらをどのように使用する必要があるかです: [Android.Runtime.Register("getMinBufferSize", "(III)I", "")] [Android.Runtime.GeneratedEnum] [Android. Runtime.GeneratedEnum]

Java のコードはより簡単でした。

int buffsize = AudioTrack.getMinBufferSize(_sampleRate, 
AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);

ここで、_sampleRate は int _sampleRate = 44100; です。は度数率を表します。

したがって、少なくとも xamarin ドキュメントの括弧内の 3 行が何であるかを教えていただければ、とても感謝しています。

よろしくお願いいたします。良い一日をお過ごしください。

これまでの私のコード:

namespace simple_synth
{

[Activity (Label = "_secondAct")]   //activity that opens the second screen     
public class _secondAct : Activity
{

Thread _thread; //audio processing thread    
int _sRate = 44100; //sampling rate
bool isRunning = true;  //switch on/off

protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout._secondLay);

Button btn2 = FindViewById<Button> (Resource.Id.myButton_synth);
_audio _audioSound = new _audio ();


btn2.Click += (sender, e) => {

btn2.Text = "GOOD";
Thread _audioThread = new Thread(_audioSound._makeSound);
_audioThread.Start(); 
Console.WriteLine("audio thread: started");
while (!_audioThread.IsAlive);
Thread.Sleep(1000);
_audioSound._stopRequest();
_audioThread.Join();
Console.WriteLine("audio thread: terminated now!");
_audioSound._startRequest();
};
}
}//_secondAct

public class _audio{

private volatile bool _stopItNow;

public void _makeSound(){   // This method will be called when the thread is started. 

while (!_stopItNow) {

Console.WriteLine ("audio thread: is playing the sound...");
AudioTrack _audioTrack = new AudioTrack (Stream.Music, 22050, 
ChannelConfiguration.Mono, 
Android.Media.Encoding.Pcm16bit, 
_audBuffer.Length, AudioTrackMode.Stream);

_audioTrack.Play ();
_audioTrack.Write (_audBuffer, 0, _audBuffer.Length);
}

Console.WriteLine ("audio thread: terminated.");

} //doWork

public void _stopRequest()
{
_stopItNow = true;
}

public void _startRequest()
{
_stopItNow = false;
}
}
}
4

1 に答える 1