Repository: ggerganov/whisper.cpp
File: src/whisper.cpp (C++)

Code before:

    if (processed_diff == 0) {
        return lower->original_time;
    }

    // Perform linear interpolation
    return lower->original_time + (offset * original_diff) / processed_diff;
}

// Function to get the starting timestamp of a segment
int64_t whisper_full_get_segment_t0_from_state(struct whisper_state* state, int i_segment) {
    // If VAD wasn't used, return the original timestamp
    if (!state->has_vad_segments || !state->vad_mapping_table_initialized ||
        state->vad_mapping_table.empty()) {
        return state->result_all[i_segment].t0;
    }

    // Get the processed timestamp
    int64_t t0 = state->result_all[i_segment].t0;

    // Map to original time using the mapping table
    return map_processed_to_original_time(t0, state->vad_mapping_table);
}

// Function to get the ending timestamp of a segment
int64_t whisper_full_get_segment_t1_from_state(struct whisper_state* state, int i_segment) {
    // If VAD wasn't used, return the original timestamp
    if (!state->has_vad_segments || !state->vad_mapping_table_initialized ||
        state->vad_mapping_table.empty()) {
        return state->result_all[i_segment].t1;
    }

    // Get the processed timestamp
    int64_t t1 = state->result_all[i_segment].t1;

    // Map to original time using the mapping table
    int64_t orig_t1 = map_processed_to_original_time(t1, state->vad_mapping_table);

    // Get the corresponding t0 for this segment
    int64_t orig_t0 = whisper_full_get_segment_t0_from_state(state, i_segment);

    // Ensure minimum duration to prevent zero-length segments
    const int64_t min_duration = 10; // 10ms minimum
    if (orig_t1 - orig_t0 < min_duration) {
        orig_t1 = orig_t0 + min_duration;
    }

    return orig_t1;
}



Review comment (suggestion):
```suggestion
int64_t whisper_full_get_segment_t1_from_state(struct whisper_state * state, int i_segment) {
```

Code after:
        return lower->original_time;
    }

    // Perform linear interpolation
    return lower->original_time + (offset * original_diff) / processed_diff;
}

// Function to get the starting timestamp of a segment
int64_t whisper_full_get_segment_t0_from_state(struct whisper_state * state, int i_segment) {
    // If VAD wasn't used, return the original timestamp
    if (!state->has_vad_segments || state->vad_mapping_table.empty()) {
        return state->result_all[i_segment].t0;
    }

    // Get the processed timestamp
    int64_t t0 = state->result_all[i_segment].t0;

    // Map to original time using the mapping table
    return map_processed_to_original_time(t0, state->vad_mapping_table);
}

// Function to get the ending timestamp of a segment
int64_t whisper_full_get_segment_t1_from_state(struct whisper_state * state, int i_segment) {
    // If VAD wasn't used, return the original timestamp
    if (!state->has_vad_segments || state->vad_mapping_table.empty()) {
        return state->result_all[i_segment].t1;
    }

    // Get the processed timestamp
    int64_t t1 = state->result_all[i_segment].t1;

    // Map to original time using the mapping table
    int64_t orig_t1 = map_processed_to_original_time(t1, state->vad_mapping_table);

    // Get the corresponding t0 for this segment
    int64_t orig_t0 = whisper_full_get_segment_t0_from_state(state, i_segment);

    // Ensure minimum duration to prevent zero-length segments
    const int64_t min_duration = 10; // 10ms minimum
    if (orig_t1 - orig_t0 < min_duration) {
        orig_t1 = orig_t0 + min_duration;
    }

    return orig_t1;
}


int64_t whisper_full_get_segment_t0(struct whisper_context * ctx, int i_segment) {
    return whisper_full_get_segment_t0_from_state(ctx->state, i_segment);
}