0

我需要使用应用效果将输出文件写入外部存储,但不知道如何执行此操作。任何帮助都将非常感谢您制作带有效果的音频输出 mp3 或 mp4 文件。我已经成功地完成了实时音高变化,我已经使用了一些将文件写入外部存储的代码,但生成的文件只有 0 字节并且已损坏。我使用了以下代码

 const char *output1 = "/storage/emulated/0/Music/123456.mp3";
const char *openError = decoder->open(input, false, 0, 0, 0);
if (openError) {
    delete decoder;
    return false;
};

FILE *fd = createWAV(output1, decoder->samplerate, 2);
if (!fd) {
    delete decoder;
    return false;
};

float effectMix = 0.5f;
SuperpoweredFX *effect = NULL;
if (effectId == 0) {
    player->setPitchShift(10);
    effect = new SuperpoweredEcho(decoder->samplerate);
    ((SuperpoweredEcho *) effect)->setMix(effectMix);
} else if (effectId == 1) {
    effect = new SuperpoweredReverb(decoder->samplerate);
    ((SuperpoweredReverb *) effect)->setMix(effectMix);
}

if (effect == NULL) {
    delete decoder;
    return false;
}

effect->enable(true);
short int *intBuffer = (short int *) malloc(
decoder->samplesPerFrame * 2 * sizeof(short int) + 16384);
float *floatBuffer = (float *) malloc(decoder->samplesPerFrame * 2 * sizeof(float) + 1024);
unsigned int samplesDecoded;
while (true) {
    samplesDecoded = decoder->samplesPerFrame;
    if (decoder->decode(intBuffer, &samplesDecoded) == SUPERPOWEREDDECODER_ERROR) {
        break;
    }
    if (samplesDecoded < 1) {
        break;
    }

    SuperpoweredShortIntToFloat(intBuffer, floatBuffer, samplesDecoded);

    effect->process(floatBuffer, floatBuffer, samplesDecoded);

    // Convert the PCM samples from 32-bit floating point to 16-bit integer.
    SuperpoweredFloatToShortInt(floatBuffer, intBuffer, samplesDecoded);
}


fwrite(intBuffer, 1, samplesDecoded * 4, fd);
closeWAV(fd);
delete decoder;
delete effect;
free(intBuffer);
free(floatBuffer);
return true;

请帮助使用此代码。

我有如下错误。

    11-14 14:48:35.447 10065-10065/? I/art: Late-enabling -Xcheck:jni
    VMHOOK: rlim_cur : 0 pid:10065
11-14 14:48:35.497 10065-10070/? E/art: Failed sending reply to debugger: Broken pipe
11-14 14:48:35.507 10065-10070/? I/art: Debugger is no longer active
11-14 14:48:35.537 10065-10065/? I/MultiDex: VM with version 2.1.0 has multidex support
    Installing application
    VM has multidex support, MultiDex support library is disabled.
11-14 14:48:35.627 10065-10065/? V/FA: Registered activity lifecycle callback
11-14 14:48:35.647 10065-10065/? D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
    com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
11-14 14:48:35.647 10065-10065/? I/FirebaseInitProvider: FirebaseApp initialization successful
11-14 14:48:35.847 10065-10080/? V/FA: Collection enabled
    App package, google app id: com.korakoepitchchanger, 1:872304933700:android:c6dbb37cfd23f040
11-14 14:48:35.847 10065-10080/? I/FA: App measurement is starting up, version: 13001
    To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
    To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.korakoepitchchanger
11-14 14:48:35.847 10065-10080/? D/FA: Debug-level message logging enabled
11-14 14:48:35.947 10065-10080/? V/FA: Connecting to remote service
11-14 14:48:36.127 10065-10080/? V/FA: Connection attempt already in progress
11-14 14:48:36.497 10065-10065/? V/FA: onActivityCreated
11-14 14:48:36.557 10065-10080/com.korakoepitchchanger I/FA: Tag Manager is not found and thus will not be used
11-14 14:48:36.587 10065-10080/com.korakoepitchchanger D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=SplashActivity, firebase_screen_id(_si)=2861861576925568549}]
11-14 14:48:36.657 10065-10080/com.korakoepitchchanger V/FA: Connection attempt already in progress
    Connection attempt already in progress
    Activity resumed, time: 187857395
11-14 14:48:36.707 10065-10080/com.korakoepitchchanger D/FA: Connected to remote service
11-14 14:48:36.707 10065-10080/com.korakoepitchchanger V/FA: Processing queued up service tasks: 4
11-14 14:48:37.077 10065-10080/com.korakoepitchchanger V/FA: Screen exposed for less than 1000 ms. Event not sent. time: 530
    Activity paused, time: 187857925
11-14 14:48:37.217 10065-10065/com.korakoepitchchanger V/FA: onActivityCreated
11-14 14:48:37.377 10065-10065/com.korakoepitchchanger I/CrashlyticsCore: Initializing Crashlytics 2.6.3.25
11-14 14:48:37.437 10065-10164/com.korakoepitchchanger D/libc: [NET] android_getaddrinfofornetcontext+,hn 24(0x73657474696e67),sn(),hints(known),family 0,flags 1024, proc=com.korakoepitchchanger
    [NET] android_getaddrinfo_proxy get netid:0
11-14 14:48:37.457 10065-10164/com.korakoepitchchanger D/libc: [NET] android_getaddrinfo_proxy-, success
11-14 14:48:37.997 10065-10065/com.korakoepitchchanger I/DynamiteModule: Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:10900
    Selected remote version of com.google.android.gms.ads.dynamite, version >= 10900
11-14 14:48:38.097 10065-10065/com.korakoepitchchanger W/System: ClassLoader referenced unknown path: /data/data/com.google.android.gms/app_chimera/m/00000034/n/arm64-v8a
11-14 14:48:38.167 10065-10065/com.korakoepitchchanger D/DynamitePackage: Instantiated singleton DynamitePackage.
    Instantiating com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImpl
11-14 14:48:38.797 10065-10065/com.korakoepitchchanger I/WebViewFactory: Loading com.google.android.webview version 70.0.3538.80 (code 353808050)
11-14 14:48:39.077 10065-10164/com.korakoepitchchanger D/libc: [NET] android_getaddrinfofornetcontext+,hn 19(0x6170692e637261),sn(),hints(known),family 0,flags 1024, proc=com.korakoepitchchanger
11-14 14:48:39.087 10065-10164/com.korakoepitchchanger D/libc: [NET] android_getaddrinfo_proxy get netid:0
11-14 14:48:39.107 10065-10164/com.korakoepitchchanger D/libc: [NET] android_getaddrinfo_proxy-, success
11-14 14:48:39.317 10065-10075/com.korakoepitchchanger I/art: Background sticky concurrent mark sweep GC freed 8353(1299KB) AllocSpace objects, 5(100KB) LOS objects, 1% free, 101MB/102MB, paused 1.796ms total 102.918ms
11-14 14:48:39.327 10065-10065/com.korakoepitchchanger I/art: Rejecting re-init on previously-failed class java.lang.Class<hs>
    Rejecting re-init on previously-failed class java.lang.Class<hs>
11-14 14:48:39.387 10065-10065/com.korakoepitchchanger I/cr_LibraryLoader: Time to load native libraries: 2 ms (timestamps 1635-1637)
11-14 14:48:39.647 10065-10065/com.korakoepitchchanger I/chromium: [INFO:library_loader_hooks.cc(36)] Chromium logging enabled: level = 0, default verbosity = 0
11-14 14:48:39.657 10065-10065/com.korakoepitchchanger I/cr_LibraryLoader: Expected native library version number "70.0.3538.80", actual native library version number "70.0.3538.80"
11-14 14:48:39.807 10065-10065/com.korakoepitchchanger I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
11-14 14:48:39.867 10065-10075/com.korakoepitchchanger W/art: Suspending all threads took: 54.598ms
11-14 14:48:39.877 10065-10075/com.korakoepitchchanger I/art: Background sticky concurrent mark sweep GC freed 10288(811KB) AllocSpace objects, 2(40KB) LOS objects, 0% free, 101MB/102MB, paused 57.343ms total 82.106ms
11-14 14:48:40.657 10065-10164/com.korakoepitchchanger W/CrashlyticsCore: Expected method missing: registerOnMeasurementEventListener
    java.lang.NoSuchMethodException: parameter type is null
        at java.lang.Class.getMethod(Class.java:616)
        at java.lang.Class.getDeclaredMethod(Class.java:586)
        at com.crashlytics.android.c.u.a(Unknown Source)
        at com.crashlytics.android.c.u.a(Unknown Source)
        at com.crashlytics.android.c.k.a(Unknown Source)
        at com.crashlytics.android.c.l.d(Unknown Source)
        at com.crashlytics.android.c.l.f(Unknown Source)
        at b.a.a.a.h.a(Unknown Source)
        at b.a.a.a.h.a(Unknown Source)
        at b.a.a.a.a.c.a$2.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)
11-14 14:48:41.177 10065-10317/com.korakoepitchchanger W/cr_media: Requires BLUETOOTH permission
11-14 14:48:41.207 10065-10337/com.korakoepitchchanger E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
11-14 14:48:41.207 10065-10337/com.korakoepitchchanger I/Adreno: QUALCOMM build                   : 8249e7b, Iacb76f3f7d
    Build Date                       : 03/22/16
    OpenGL ES Shader Compiler Version: XE031.06.00.05
    Local Branch                     : 
    Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.BR.1.2.6_RB1.06.00.01.179.016
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
11-14 14:48:41.427 10065-10065/com.korakoepitchchanger D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
11-14 14:48:41.437 10065-10313/com.korakoepitchchanger D/libc: [NET] android_getaddrinfofornetcontext+,hn 27(0x676f6f676c6561),sn(),hints(known),family 0,flags 1024, proc=com.korakoepitchchanger
    [NET] android_getaddrinfo_proxy get netid:0
11-14 14:48:41.457 10065-10313/com.korakoepitchchanger D/libc: [NET] android_getaddrinfo_proxy-, success
11-14 14:48:41.497 10065-10337/com.korakoepitchchanger W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
11-14 14:48:41.577 10065-10337/com.korakoepitchchanger W/VideoCapabilities: Unsupported mime video/x-ms-wmv
11-14 14:48:41.597 10065-10337/com.korakoepitchchanger W/AudioCapabilities: Unsupported mime audio/qcelp
11-14 14:48:41.607 10065-10337/com.korakoepitchchanger W/AudioCapabilities: Unsupported mime audio/x-ms-wma
    Unsupported mime audio/qcelp
11-14 14:48:41.607 10065-10337/com.korakoepitchchanger W/VideoCapabilities: Unsupported mime video/x-ms-wmv
11-14 14:48:41.617 10065-10337/com.korakoepitchchanger W/AudioCapabilities: Unsupported mime audio/ac3
11-14 14:48:41.637 10065-10065/com.korakoepitchchanger I/Ads: Updating ad debug logging enablement.
11-14 14:48:41.677 10065-10075/com.korakoepitchchanger W/art: Suspending all threads took: 8.034ms
11-14 14:48:41.687 10065-10075/com.korakoepitchchanger I/art: Background sticky concurrent mark sweep GC freed 3313(196KB) AllocSpace objects, 0(0B) LOS objects, 0% free, 102MB/102MB, paused 12.936ms total 70.241ms
11-14 14:48:41.747 10065-10075/com.korakoepitchchanger W/art: Suspending all threads took: 8.534ms
11-14 14:48:41.757 10065-10075/com.korakoepitchchanger I/art: Background partial concurrent mark sweep GC freed 12066(895KB) AllocSpace objects, 2(120KB) LOS objects, 13% free, 102MB/118MB, paused 11.969ms total 73.844ms
11-14 14:48:41.777 10065-10065/com.korakoepitchchanger I/Ads: Starting ad request.
    SDK version: afma-sdk-a-v14574021.12451000.1
    Use AdRequest.Builder.addTestDevice("8884694ABCF6A031A5CA1B31EF06F481") to get test ads on this device.
11-14 14:48:41.777 10065-10065/com.korakoepitchchanger W/Ads: Not retrying to fetch app settings
11-14 14:48:41.797 10065-10337/com.korakoepitchchanger I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
11-14 14:48:41.957 10065-10080/com.korakoepitchchanger D/FA: Logging event (FE): _vs, Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=SplashActivity, firebase_previous_id(_pi)=2861861576925568549, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=2861861576925568551}]
11-14 14:48:42.047 10065-10236/com.korakoepitchchanger W/Ads: Update ad debug logging enablement as false
11-14 14:48:42.067 10065-10080/com.korakoepitchchanger V/FA: Activity resumed, time: 187862712
11-14 14:48:42.847 10065-10077/com.korakoepitchchanger W/Ads: There was a problem getting an ad response. ErrorCode: 0
11-14 14:48:42.877 10065-10080/com.korakoepitchchanger D/FA: Logging event (FE): ad_query(_aq), Bundle[{firebase_event_origin(_o)=am, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=2861861576925568551, ad_event_id(_aeid)=2861861576925568550}]
11-14 14:48:42.927 10065-10065/com.korakoepitchchanger W/Ads: Failed to load ad: 0
11-14 14:48:43.237 10065-10065/com.korakoepitchchanger E/=>>>: Visible
11-14 14:48:47.897 10065-10080/com.korakoepitchchanger V/FA: Activity paused, time: 187868740
11-14 14:48:47.897 10065-10080/com.korakoepitchchanger D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=6028, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=2861861576925568551}]
11-14 14:48:51.817 10065-10080/com.korakoepitchchanger V/FA: Activity resumed, time: 187872663
    Screen exposed for less than 1000 ms. Event not sent. time: 7
11-14 14:48:51.827 10065-10080/com.korakoepitchchanger V/FA: Activity paused, time: 187872669
11-14 14:48:52.017 10065-10065/com.korakoepitchchanger V/FA: onActivityCreated
11-14 14:48:52.087 10065-10065/com.korakoepitchchanger I/>>>: applied
11-14 14:48:52.097 10065-10065/com.korakoepitchchanger I/>>>: applied
11-14 14:48:52.097 10065-10065/com.korakoepitchchanger E/>>>: /storage/emulated/0/Music/123.mp3
11-14 14:48:52.187 10065-10065/com.korakoepitchchanger I/>>>: applied
11-14 14:48:52.207 10065-10065/com.korakoepitchchanger E/>>>>: 30
11-14 14:48:52.257 10065-10080/com.korakoepitchchanger D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=MainActivity, firebase_previous_id(_pi)=2861861576925568551, firebase_screen_class(_sc)=Temp2Activity, firebase_screen_id(_si)=2861861576925568552}]
11-14 14:48:52.377 10065-10080/com.korakoepitchchanger V/FA: Activity resumed, time: 187873057
11-14 14:48:53.137 10065-10065/com.korakoepitchchanger W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: /storage/emulated/0/Music/123.mp3
11-14 14:48:53.137 10065-10065/com.korakoepitchchanger V/MediaPlayer: network type=wifi
11-14 14:48:53.167 10065-10065/com.korakoepitchchanger I/MediaPlayer: It's not a proxy project.
11-14 14:48:53.167 10065-10065/com.korakoepitchchanger D/MediaPlayer: ANDROID_HTC_INVOKE_GET_CALLING_PROCESS packageName: com.korakoepitchchanger
11-14 14:48:53.247 10065-10065/com.korakoepitchchanger D/MediaPlayer: setSubtitleAnchor in MediaPlayer
11-14 14:48:53.307 10065-10065/com.korakoepitchchanger E/>>>>: 30
11-14 14:48:54.307 10065-10065/com.korakoepitchchanger E/>>>>: 30
11-14 14:48:54.577 10065-10761/com.korakoepitchchanger A/libc: invalid address or address of corrupt block 0x5570b17e30 passed to dlfree
11-14 14:48:54.777 10065-10761/com.korakoepitchchanger W/google-breakpad: Failed to generate minidump.
11-14 14:48:54.877 10065-10761/com.korakoepitchchanger W/google-breakpad: ### ### ### ### ### ### ### ### ### ### ### ### ###
    Chrome build fingerprint:
    70.0.3538.80
    353808050
    ### ### ### ### ### ### ### ### ### ### ### ### ###
11-14 14:48:54.877 10065-10761/com.korakoepitchchanger A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xdeadbaad in tid 10761 (AsyncTask #1)
11-14 14:48:56.687 10065-10759/com.korakoepitchchanger W/AudioTrack: releaseBuffer() track 0x5570bad4f0 disabled due to previous underrun, restarting
4

1 回答 1

2

错误日志显示了一些 firebase 问题,但在代码中发现的一个主要问题是您已将

fwrite(intBuffer, 1, samplesDecoded * 4, fd);

在while循环之外。

它应该在其中,因为 intBuffer 在每次迭代中都充满了音频数据块。

于 2018-11-14T09:56:13.590 回答