suxiaolincalendar的专栏

本文记录在学习声波传递信息技术过程中的点滴。用过支付宝当面付的同学都知道,当面付其实是传递的一个用户的编码,个人理解为后台实时产生的关联用户ID的唯一编号(实时有效)。

声波调制解调涉及信号处理技术,本文中涉及到概念解释均为个人理解,不正确的地方望纠正。

先来看两个概念:

为了便于对信号的处理,人们将原本不好处理的时域信号转换为频域,这也就是频域的作用。

声波传递信息,我们需要把信息变成声音数据,通过扬声器对外发出。

第一步:信息是什么?

音符

频率Hz

周期μs

低1Do

262

3816

低2Re

294

3401

低3Mi

330

3030

低4Fa

349

2865

低5So

392

2551

低6La

440

2272

低7Si

494

2024

高1Do

1047

955

高2Re

1175

851

高3Mi

1319

758

高4Fa

1397

751

高5So

1568

637

高6La

1760

568

高7Si

1967

508

知道要传递的信息实质是一连串特定频率了就好办了。

第二步:如何把信息变成声音数据?

publicAudioTrack(int streamType, int sampleRateInHz, int channelConfig, intaudioFormat, int bufferSizeInBytes, int mode)

参数说明:

streamType

, and.

sampleRateInHz

the initial source sample rate expressed in Hz.

channelConfig

audioFormat

, and.

bufferSizeInBytes

the total size (in bytes) of the buffer where audio data is read from for playback. If using the AudioTrack in streaming mode, you can write data into this buffer in smaller chunks than this size. If using the AudioTrack in static mode, this is the maximum size of the sound that will be played for this instance. SeegetMinBufferSize(int, int, int)to determine the minimum required buffer size for the successful creation of an AudioTrack instance in streaming mode. Using values smaller than getMinBufferSize() will result in an initialization failure.

mode

这些数据只需要设定就可以了:

public intwrite(short [] audioData, int offsetInBytes, int sizeInBytes)

audioData

the array that holds the data to play.

offsetInBytes

the offset expressed in bytes in audioData where the data to play starts.

sizeInBytes

the number of bytes to read in audioData after the offset.

b> 播放偏移

根据AudioTrack的参数,生成数据。

第三步:采集音频数据,呵呵常说的录音AudioRecord ()

publicAudioRecord(int audioSource, int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)

Added in

Class constructor. Though some invalid parameters will result in anIllegalArgumentExceptionexception, other errors do not. Thus you should callimmediately after construction to confirm that the object is usable.

Parameters

audioSourcethe recording source (also referred to as capture preset). SeeMediaRecorder.AudioSourcefor the capture preset definitions.

sampleRateInHzthe sample rate expressed in Hertz. 44100Hz is currently the only rate that is guaranteed to work on all devices, but other rates such as 22050, 16000, and 11025 may work on some devices.

channelConfigdescribes the configuration of the audio channels. Seeand.is guaranteed to work on all devices.

audioFormatthe format in which the audio data is represented. Seeand

bufferSizeInBytesthe total size (in bytes) of the buffer where audio data is written to during the recording. New audio data can be read from this buffer in smaller chunks than this size. SeegetMinBufferSize(int, int, int)to determine the minimum required buffer size for the successful creation of an AudioRecord instance. Using values smaller than getMinBufferSize() will result in an initialization failure.

比较简单,读取到预先设定的buffer里就好了。

第四步:也就是关键步骤,对第三步中读取的数据进行FFT,到的信号的频率,根据频率值去对应我们第一步中所说的音频标准中,取得数据。

至此声波传递信息的步骤的做了记录。我的代码,非常粗糙,由于设置的阀值比较高,传输距离比较短。

纸上得来终觉浅,绝知此事要躬行,,有兴趣可以自己试试。

而有的旅行是释放负面情绪,换个心情,轻装上阵。

suxiaolincalendar的专栏

相关文章:

你感兴趣的文章:

标签云: