Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info outlet to sfload, use canvas_open instead of open_via_path #2278

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add info outlet to sfload
timothyschoen committed Jan 29, 2025
commit 4034dd0b44feb3682b6864f95ab601070cdb5f87
37 changes: 29 additions & 8 deletions Source/Control/sfload.c
Original file line number Diff line number Diff line change
@@ -10,8 +10,9 @@

static t_class *sfload_class;

typedef struct _sfload{
typedef struct _sfload {
t_object x_obj;
t_outlet *x_info_outlet;
AVCodecContext *x_stream_ctx;
int x_stream_idx;
AVPacket *x_pkt;
@@ -27,6 +28,7 @@ typedef struct _sfload{
_Atomic int x_result_ready;
t_clock *x_result_clock;
char x_path[MAXPDSTRING];
t_atom x_sfinfo[6];
}t_sfload;

void* sfload_read_audio(void *arg){ // read audio into array
@@ -85,6 +87,10 @@ void* sfload_read_audio(void *arg){ // read audio into array
pd_error(x, "[sfload]: Could not initialize the resampling context\n");
return (NULL);
}

AVDictionaryEntry *loop_start_entry = av_dict_get(x->x_ic->metadata, "loop_start", NULL, 0);
AVDictionaryEntry *loop_end_entry = av_dict_get(x->x_ic->metadata, "loop_end", NULL, 0);

t_sample* x_out = (t_sample*)av_mallocz(nch * FRAMES * sizeof(t_sample));
int output_index = 0;
while(av_read_frame(x->x_ic, x->x_pkt) >= 0) {
@@ -111,6 +117,14 @@ void* sfload_read_audio(void *arg){ // read audio into array
}
av_packet_unref(x->x_pkt);
}

SETFLOAT(x->x_sfinfo, x->x_stream_ctx->sample_rate);
SETFLOAT(x->x_sfinfo + 1, nch);
SETFLOAT(x->x_sfinfo + 2, av_get_bytes_per_sample(x->x_stream_ctx->sample_fmt) * 8);
SETFLOAT(x->x_sfinfo + 3, output_index);
SETFLOAT(x->x_sfinfo + 4, loop_start_entry ? atoi(loop_start_entry->value) : 0);
SETFLOAT(x->x_sfinfo + 5, loop_end_entry ? atoi(loop_end_entry->value) : 0);

x->x_result_ready = output_index;
av_free(x_out);
return (NULL);
@@ -127,18 +141,24 @@ void sfload_check_done(t_sfload* x){ // result clock
x->x_result_ready = 0;
free(x->x_all_out);
x->x_all_out = NULL;
outlet_list(x->x_info_outlet, &s_, 6, x->x_sfinfo);
}
else
clock_delay(x->x_result_clock, 20);
}

static void sfload_find_file(t_sfload *x, t_symbol* file, char* dir_out, char* filename_out){
const char *filename = file->s_name;
const char *dirname = canvas_getdir(x->x_canvas)->s_name;
char* fileout;
open_via_path(dirname, filename, "", dir_out, &fileout, MAXPDSTRING-1, 0);
memcpy(filename_out, fileout, strlen(fileout) + 1);
strcat(dir_out, "/");
static void sfload_find_file(t_sfload *x, t_symbol* file, char* dir_out){
static char fname[MAXPDSTRING];
char *bufptr;
int fd = canvas_open(x->x_canvas, file->s_name, "", fname, &bufptr, MAXPDSTRING, 1);
if(fd < 0){
post("[sfload] file '%s' not found", file->s_name);
return;
}
else {
if(bufptr > fname) bufptr[-1] = '/';
strcpy(dir_out, fname);
}
}

void sfload_load(t_sfload* x, t_symbol* s, int ac, t_atom* av){
@@ -202,6 +222,7 @@ static void *sfload_new(t_symbol *s, int ac, t_atom *av){
x->x_canvas = canvas_getcurrent();
x->x_result_ready = 0;
x->x_result_clock = clock_new(x, (t_method)sfload_check_done);
x->x_info_outlet = outlet_new(x, &s_list);
return(x);
}