简体   繁体   English

Android上的声波通信

[英]Sound wave communication on Android

I want to transfer data by sound wave on android phone, and I find this example : https://github.com/JesseGu/SinVoice 我想通过Android手机上的声波传输数据,我发现这个例子: https//github.com/JesseGu/SinVoice

this project work fine, when it transfer data, I can hear sound and transfer data success. 这个项目工作正常,当它传输数据时,我可以听到声音并传输数据成功。

Problem is how to modify code for it transfer data but i hear no sound ? 问题是如何修改代码以传输数据,但我听不到声音?
If is used high frequency sound, please tell how to modify it ,thanks. 如果使用高频声音,请告诉我如何修改它,谢谢。

Chirp for iPhone is a cheap way out of solving a difficult problem. 用于iPhone的Chirp是一种解决难题的廉价方法。 They actually upload the data to be sent online, the "chirp" appears to just be a unique sequence of notes which indexes to the uploaded data on the online database. 他们实际上传了要在线发送的数据,“唧唧”似乎只是一个独特的音符序列,它索引在线数据库上传的数据。 That being said, I have been interested in genuine, audio data transmission for quite some time now. 话虽这么说,我现在对真正的音频数据传输感兴趣了很长一段时间。 If you're going to do this project, you need to worry about the code yourself, what I can show you is a bunch of technologies you may want to incorporate into your design. 如果你要做这个项目,你需要自己担心代码,我可以向你展示的是你可能希望融入设计的一系列技术。 My advice would be to start from scratch, but you could try building off of this Github code if you really want to. 我的建议是从头开始,但如果你真的想要,你可以尝试构建这个Github代码。

For detecting and filtering out sounds, use the Goertzel algorithm. 要检测和过滤声音,请使用Goertzel算法。 For an input sound, the Goertzel algorithm filters the stream of incoming sound samples and produces a complex valued stream of output values ( a+bi ). 对于输入声音,Goertzel算法过滤输入声音样本流并产生复数值的输出值流(a + bi)。 The magnitude ( sqrt((a^2)+(b^2)) ) of the values gives the intensity of a particular frequency at the given point in time. 值的大小(sqrt((a ^ 2)+(b ^ 2)))给出给定时间点的特定频率的强度。 The angle ( atan2(b,a) ) of the values gives the phase of that frequency at the given point in time. 值的角度(atan2(b,a))给出了给定时间点的该频率的相位。 You can choose which frequency you want to filter on and, in particular, use multiple instances of the Goertzel algorithm to detect multiple frequencies. 您可以选择要过滤的频率,特别是使用Goertzel算法的多个实例来检测多个频率。

http://www.mstarlabs.com/dsp/goertzel/goertzel.html http://www.mstarlabs.com/dsp/goertzel/goertzel.html

You can simply play a pattern using one tone, being on or off, filter the sound coming in through the microphone using the Goertzel algorithm, and use that to detect the pattern played, thus recovering the bits of information you sent. 您可以使用一种音调,打开或关闭,使用Goertzel算法过滤通过麦克风传入的声音,然后使用它来检测播放的模式,从而恢复您发送的信息位。 This technique is a simple form of amplitude modulation and is very susceptible to background noise. 该技术是幅度调制的简单形式,并且非常容易受到背景噪声的影响。 Your data transfer rate will be very slow. 您的数据传输速度将非常慢。

https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Amplitude_modulation.html https://www.princeton.edu/~achaney/tmve/wiki100k/docs/Amplitude_modulation.html

You can filter for several different notes and have your program listen for sequences of notes. 您可以过滤几种不同的音符,让程序监听音符序列。 This is most likely how Chirp works internally, and this is very reliable. 这很可能是Chirp内部工作的方式,这非常可靠。 Your data transfer rate can be somewhat improved. 您的数据传输速率可以有所改善。

You can also use frequency modulation or phase modulation. 您也可以使用频率调制或相位调制。 Using the Goertzel Algorithm will mean phase modulation is somewhat easier than frequency modulation. 使用Goertzel算法意味着相位调制比频率调制更容易。 I have not tested this approach as extensively, but it appears to be incredibly reliable and the bit rates could be higher than amplitude modulation. 我没有广泛地测试这种方法,但它看起来非常可靠,比特率可能高于幅度调制。 I once wrote a program that sent pictures using phase modulation. 我曾经写过一个使用相位调制发送图片的程序。 The data was not digitized, I just determined pixel intensity by phase and scanned across all of the pixels in my image. 数据没有数字化,我只是按相位确定像素强度并扫描图像中的所有像素。 The picture came out fairly clear even when playing loud music. 即使在播放嘈杂的音乐时,画面也相当清晰。 Note that the images were fairly small and it still took a couple minutes to send, the bitrates for all audio communication are going to be pretty low. 请注意,图像相当小,仍然需要几分钟才能发送,所有音频通信的比特率都会非常低。

http://www.circuitstoday.com/modulation http://www.circuitstoday.com/modulation

One quick word of advice. 一个快速的建议。 Consider these two ways of calculating a sine wave to play 考虑这两种计算正弦波的方法

double output[length];
double t=0;
double samplerate=44100.0;
double frequency=440.0;
double w=2*pi*frequency;
double time_increment=1.0/samplerate;
for(n=0;n<length;n++) {
    output[n]=sin(w*t);
    t+=time_increment;
}

Second way 第二种方式

double output[length];
double samplerate=44100.0;
double frequency=440.0;
double phase=0;
double phase_increment=2*pi*frequency/samplerate;
double tau=2*pi;
for(n=0;n<length;n++) {
    output[n]=sin(phase);
    phase=(phase+phase_increment)%tau;
}

For the first way, when you have large values of t, the value inside the sin will lose precision. 对于第一种方式,当你有大的t值时,sin内的值将失去精度。 Essentially, the longer you play the note for, the crappier it sounds. 从本质上讲,你演奏音符的时间越长,听起来就越糟糕。 After not too long, it begins to sound very impure. 不久之后,它开始听起来非常不纯净。

The second way avoids this problem by integrating the phase over time and modding (%) it by 2*pi (tau), keeping the value in the range 0 to 2pi. 第二种方法通过将相位随时间积分并将其修改(%)2 * pi(tau)来避免这个问题,将值保持在0到2pi的范围内。

Here's an Android implementation of Chirp , which maps data to frequencies of sound. 这是一个ChirpAndroid实现 ,它将数据映射到声音频率。 In addition, to mitigate data loss, transmitted frames of data are supported by error correction symbols. 另外,为了减轻数据丢失,发送的数据帧由纠错符号支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM