Skip to content

Commit

Permalink
mnt : include guard + remove enum class (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
PABannier authored May 10, 2024
1 parent 1c39c4c commit fa06a15
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
22 changes: 14 additions & 8 deletions bark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ struct bark_context {
bark_codes coarse_tokens;
bark_codes fine_tokens;

std::vector<float> audio_arr;
float * generated_audio = NULL;
int n_generated_samples = 0;

// hyperparameters
bark_context_params params;
Expand Down Expand Up @@ -1173,7 +1174,10 @@ static bool bark_load_model_from_file(

// codec model
{
bctx->encodec_ctx = encodec_load_model(fin, n_gpu_layers);
const int offset = fin.tellg();
fin.close();

bctx->encodec_ctx = encodec_load_model(fname.c_str(), offset, n_gpu_layers);
if (!bctx->encodec_ctx) {
fprintf(stderr, "%s: invalid model file '%s' (bad encodec)\n", __func__, fname.c_str());
return false;
Expand Down Expand Up @@ -2220,12 +2224,14 @@ bool bark_generate_audio(struct bark_context* bctx, const char * text, int n_thr
}
}

if (!encodec_decompress_audio(bctx->encodec_ctx, encodec_tokens, n_threads)) {
if (!encodec_decompress_audio(bctx->encodec_ctx, encodec_tokens.data(), encodec_tokens.size(), n_threads)) {
printf("%s: Could not generate waveform from tokens with Encodec\n", __func__);
return false;
}

bctx->audio_arr = bctx->encodec_ctx->out_audio;
bctx->generated_audio = encodec_get_audio(bctx->encodec_ctx);
bctx->n_generated_samples = encodec_get_audio_size(bctx->encodec_ctx);

bctx->stats.t_eval_us = ggml_time_us() - t_start_eval_us;

return true;
Expand Down Expand Up @@ -2427,17 +2433,17 @@ bool bark_model_quantize(const char * fname_inp, const char * fname_out, ggml_ft
}

float * bark_get_audio_data(struct bark_context *bctx) {
if (!bctx || bctx->audio_arr.empty()) {
if (!bctx) {
return nullptr;
}
return bctx->audio_arr.data();
return bctx->generated_audio;
}

int bark_get_audio_data_size(struct bark_context *bctx) {
if (!bctx || bctx->audio_arr.empty()) {
if (!bctx || bctx->generated_audio == NULL) {
return 0;
}
return bctx->audio_arr.size();
return bctx->n_generated_samples;
}

const bark_statistics * bark_get_statistics(struct bark_context *bctx) {
Expand Down
25 changes: 22 additions & 3 deletions bark.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
/*
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2024 Pierre-Antoine Bannier │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
│ PERFORMANCE OF THIS SOFTWARE. │
╚─────────────────────────────────────────────────────────────────────────────*/
#pragma once

#include "encodec.h"
#include "ggml-backend.h"
#include "ggml.h"

#ifdef __cplusplus
extern "C" {
#endif
enum class bark_verbosity_level {
LOW = 0,
enum bark_verbosity_level {
LOW = 0,
MEDIUM = 1,
HIGH = 2,
HIGH = 2,
};

struct gpt_hparams {
Expand Down
2 changes: 1 addition & 1 deletion encodec.cpp

0 comments on commit fa06a15

Please sign in to comment.