找到你要的答案

Q:Send wav data to from Java to Cpp via string

Q:把WAV数据从java cpp通过字符串

I need to be able to send a wav files to a background process in android, which is running my audio plugin code from a different package: Samsung Audio SDK.

The only interface to the background process is to send strings - thus the solution seems to be to convert the wav to a string in Java, and reload it again in cpp. The format of the wavs can be fixed (it doesn't need to account for all possible parameters)

What would be a good way to go about this? Plus are there any problems sending a gigantic string in this manner (i.e. should i break it into chunks?)

我需要能够发送一个WAV文件到Android的后台进程,这是从一个不同的包运行我的音频插件代码:三星音频SDK。

到后台进程的唯一接口发送字符串-这样的解决方案似乎是将WAV到java中的字符串,并重装一遍CPP。该方法的格式可以是固定的(不需要考虑所有可能的参数)

这将是一个好办法呢?加上有任何问题,以这种方式发送一个巨大的字符串(即我应该打破成块吗?)

answer1: 回答1:

You should put a character to separate each of the values so you can easily parse the string on the other side via splitting it up e.g. "1,2,3" -> split on "," = "1" "2" "3"

In your case I would first try to send the whole thing and see if there are any problems. If there are none... good, otherwise split the whole string into several pieces by size, but keeping the way you can split the values easily. Also you should watch that the encoding of the Strings is equal on both ends, otherwise you will have problems.

你应该把一个字符分隔的值,所以你可以很容易地解析另一边的字符串通过分拆“1,2,3”>;分裂“,”=“1”“2”“3”

在你的情况下,我会首先尝试发送整个事情,看看是否有任何问题。如果没有…好,否则整个字符串分割成几块大小,但保持的方式,您可以分裂的价值观很容易。你也应该注意,两端的字符串的编码是相等的,否则你会遇到问题。

answer2: 回答2:

I found a way to do this from the FAQ section on the Samsung Website

  1. Copy file from java to the directory pointed to by 'getApplicationInfo().dataDir'. I was having trouble using this method because I didn't set the file to be readable (e.g. outFile.setReadable(true,false); )

  2. You can read the file by doing something like this (if your package is example.com):

    void readFile() {
    
        FILE* fp = fopen("/data/data/example.com/file_test_1.txt","r+");
    
        if(fp!=NULL)
        {
            // do something
            fclose(fp);
        }
    }
    

我发现了一种方法,是从三星网站上的常见问题解答部分

  1. 复制文件从java到目录所指向的“getapplicationinfo() datadir”。我很难使用这种方法,因为我没有设置文件是可读的(例如文件。setreadable(true,false);)

  2. 您可以通过这样做来读取文件(如果您的包是示例com):

    void readFile() {
    
        FILE* fp = fopen("/data/data/example.com/file_test_1.txt","r+");
    
        if(fp!=NULL)
        {
            // do something
            fclose(fp);
        }
    }
    
java  android  c++  audio  wav